Skip to content

Commit

Permalink
fix(reconciler): remove beforeChild on replace
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett committed Mar 4, 2023
1 parent cf9bfc6 commit 5f376ce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
15 changes: 5 additions & 10 deletions packages/fiber/src/core/reconciler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export interface Instance<O = any> {
attach?: AttachType<O>
previousAttach?: any
isHidden: boolean
autoRemovedBeforeAppend?: boolean
}

interface HostConfig {
Expand Down Expand Up @@ -152,7 +151,10 @@ function insertBefore(
child.parent = parent
const childIndex = parent.children.indexOf(beforeChild)
if (childIndex !== -1) parent.children.splice(childIndex, replace ? 1 : 0, child)
if (replace) beforeChild.parent = null
if (replace) {
beforeChild.parent = null
removeChild(parent, beforeChild)
}

// Attach tree once complete
handleContainerEffects(parent, child, beforeChild, replace)
Expand Down Expand Up @@ -234,14 +236,7 @@ function switchInstance(

// Link up new instance
const parent = oldInstance.parent
if (parent) {
// Manually handle replace https://github.com/pmndrs/react-three-fiber/pull/2680
// insertBefore(parent, newInstance, oldInstance, true)

if (!oldInstance.autoRemovedBeforeAppend) removeChild(parent, oldInstance)
if (newInstance.parent) newInstance.autoRemovedBeforeAppend = true
appendChild(parent, newInstance)
}
if (parent) insertBefore(parent, newInstance, oldInstance, true)

// This evil hack switches the react-internal fiber node
// https://github.com/facebook/react/issues/14983
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,6 @@ Array [
},
Object {
"children": Array [
Object {
"children": Array [],
"props": Object {
"attach": "material",
},
"type": "meshBasicMaterial",
},
Object {
"children": Array [],
"props": Object {
Expand All @@ -404,6 +397,13 @@ Array [
},
"type": "boxGeometry",
},
Object {
"children": Array [],
"props": Object {
"attach": "material",
},
"type": "meshBasicMaterial",
},
],
"props": Object {
"position-x": 12,
Expand Down

0 comments on commit 5f376ce

Please sign in to comment.