Skip to content

Commit 730ae7a

Browse files
authored
Clear fiber.sibling field when clearing nextEffect (facebook#18970)
* Clear fiber.sibling field when clearing nextEffect
1 parent c93a6cb commit 730ae7a

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

packages/react-reconciler/src/ReactFiberCommitWork.new.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,15 +1124,16 @@ function commitNestedUnmounts(
11241124
}
11251125
}
11261126

1127-
function detachFiber(fiber: Fiber) {
1127+
function detachFiberMutation(fiber: Fiber) {
11281128
// Cut off the return pointers to disconnect it from the tree. Ideally, we
11291129
// should clear the child pointer of the parent alternate to let this
11301130
// get GC:ed but we don't know which for sure which parent is the current
11311131
// one so we'll settle for GC:ing the subtree of this child. This child
11321132
// itself will be GC:ed when the parent updates the next time.
11331133
// Note: we cannot null out sibling here, otherwise it can cause issues
11341134
// with findDOMNode and how it requires the sibling field to carry out
1135-
// traversal in a later effect. See PR #16820.
1135+
// traversal in a later effect. See PR #16820. We now clear the sibling
1136+
// field after effects, see: detachFiberAfterEffects.
11361137
fiber.alternate = null;
11371138
fiber.child = null;
11381139
fiber.dependencies_new = null;
@@ -1543,9 +1544,9 @@ function commitDeletion(
15431544
commitNestedUnmounts(finishedRoot, current, renderPriorityLevel);
15441545
}
15451546
const alternate = current.alternate;
1546-
detachFiber(current);
1547+
detachFiberMutation(current);
15471548
if (alternate !== null) {
1548-
detachFiber(alternate);
1549+
detachFiberMutation(alternate);
15491550
}
15501551
}
15511552

packages/react-reconciler/src/ReactFiberCommitWork.old.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,15 +1122,16 @@ function commitNestedUnmounts(
11221122
}
11231123
}
11241124

1125-
function detachFiber(fiber: Fiber) {
1125+
function detachFiberMutation(fiber: Fiber) {
11261126
// Cut off the return pointers to disconnect it from the tree. Ideally, we
11271127
// should clear the child pointer of the parent alternate to let this
11281128
// get GC:ed but we don't know which for sure which parent is the current
11291129
// one so we'll settle for GC:ing the subtree of this child. This child
11301130
// itself will be GC:ed when the parent updates the next time.
11311131
// Note: we cannot null out sibling here, otherwise it can cause issues
11321132
// with findDOMNode and how it requires the sibling field to carry out
1133-
// traversal in a later effect. See PR #16820.
1133+
// traversal in a later effect. See PR #16820. We now clear the sibling
1134+
// field after effects, see: detachFiberAfterEffects.
11341135
fiber.alternate = null;
11351136
fiber.child = null;
11361137
fiber.dependencies_old = null;
@@ -1541,9 +1542,9 @@ function commitDeletion(
15411542
commitNestedUnmounts(finishedRoot, current, renderPriorityLevel);
15421543
}
15431544
const alternate = current.alternate;
1544-
detachFiber(current);
1545+
detachFiberMutation(current);
15451546
if (alternate !== null) {
1546-
detachFiber(alternate);
1547+
detachFiberMutation(alternate);
15471548
}
15481549
}
15491550

packages/react-reconciler/src/ReactFiberWorkLoop.new.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,6 +1993,9 @@ function commitRootImpl(root, renderPriorityLevel) {
19931993
while (nextEffect !== null) {
19941994
const nextNextEffect = nextEffect.nextEffect;
19951995
nextEffect.nextEffect = null;
1996+
if (nextEffect.effectTag & Deletion) {
1997+
detachFiberAfterEffects(nextEffect);
1998+
}
19961999
nextEffect = nextNextEffect;
19972000
}
19982001
}
@@ -2447,6 +2450,9 @@ function flushPassiveEffectsImpl() {
24472450
const nextNextEffect = effect.nextEffect;
24482451
// Remove nextEffect pointer to assist GC
24492452
effect.nextEffect = null;
2453+
if (effect.effectTag & Deletion) {
2454+
detachFiberAfterEffects(effect);
2455+
}
24502456
effect = nextNextEffect;
24512457
}
24522458

@@ -3549,3 +3555,7 @@ export function act(callback: () => Thenable<mixed>): Thenable<void> {
35493555
};
35503556
}
35513557
}
3558+
3559+
function detachFiberAfterEffects(fiber: Fiber): void {
3560+
fiber.sibling = null;
3561+
}

packages/react-reconciler/src/ReactFiberWorkLoop.old.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,6 +2101,9 @@ function commitRootImpl(root, renderPriorityLevel) {
21012101
while (nextEffect !== null) {
21022102
const nextNextEffect = nextEffect.nextEffect;
21032103
nextEffect.nextEffect = null;
2104+
if (nextEffect.effectTag & Deletion) {
2105+
detachFiberAfterEffects(nextEffect);
2106+
}
21042107
nextEffect = nextNextEffect;
21052108
}
21062109
}
@@ -2595,6 +2598,9 @@ function flushPassiveEffectsImpl() {
25952598
const nextNextEffect = effect.nextEffect;
25962599
// Remove nextEffect pointer to assist GC
25972600
effect.nextEffect = null;
2601+
if (effect.effectTag & Deletion) {
2602+
detachFiberAfterEffects(effect);
2603+
}
25982604
effect = nextNextEffect;
25992605
}
26002606

@@ -3712,3 +3718,7 @@ export function act(callback: () => Thenable<mixed>): Thenable<void> {
37123718
};
37133719
}
37143720
}
3721+
3722+
function detachFiberAfterEffects(fiber: Fiber): void {
3723+
fiber.sibling = null;
3724+
}

0 commit comments

Comments
 (0)