Skip to content

Commit

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

interface HostConfig {
Expand Down Expand Up @@ -151,10 +152,7 @@ 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
removeChild(parent, beforeChild)
}
if (replace) beforeChild.parent = null

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

// Link up new instance
const parent = oldInstance.parent
if (parent) insertBefore(parent, newInstance, oldInstance, true)
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)
}

// 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,6 +386,13 @@ Array [
},
Object {
"children": Array [
Object {
"children": Array [],
"props": Object {
"attach": "material",
},
"type": "meshBasicMaterial",
},
Object {
"children": Array [],
"props": Object {
Expand All @@ -397,13 +404,6 @@ Array [
},
"type": "boxGeometry",
},
Object {
"children": Array [],
"props": Object {
"attach": "material",
},
"type": "meshBasicMaterial",
},
],
"props": Object {
"position-x": 12,
Expand Down

0 comments on commit 5883610

Please sign in to comment.