Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm committed May 21, 2020
1 parent f3396bf commit eb3dc35
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
9 changes: 5 additions & 4 deletions packages/react-reconciler/src/ReactFiberCommitWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -1124,15 +1124,16 @@ function commitNestedUnmounts(
}
}

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

Expand Down
9 changes: 5 additions & 4 deletions packages/react-reconciler/src/ReactFiberCommitWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -1122,15 +1122,16 @@ function commitNestedUnmounts(
}
}

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

Expand Down
8 changes: 6 additions & 2 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -1994,7 +1994,7 @@ function commitRootImpl(root, renderPriorityLevel) {
const nextNextEffect = nextEffect.nextEffect;
nextEffect.nextEffect = null;
if (nextEffect.effectTag & Deletion) {
nextEffect.sibling = null;
detachFiberAfterEffects(nextEffect);
}
nextEffect = nextNextEffect;
}
Expand Down Expand Up @@ -2451,7 +2451,7 @@ function flushPassiveEffectsImpl() {
// Remove nextEffect pointer to assist GC
effect.nextEffect = null;
if (effect.effectTag & Deletion) {
effect.sibling = null;
detachFiberAfterEffects(effect);
}
effect = nextNextEffect;
}
Expand Down Expand Up @@ -3555,3 +3555,7 @@ export function act(callback: () => Thenable<mixed>): Thenable<void> {
};
}
}

function detachFiberAfterEffects(fiber: Fiber): void {
fiber.sibling = null;
}
8 changes: 6 additions & 2 deletions packages/react-reconciler/src/ReactFiberWorkLoop.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -2102,7 +2102,7 @@ function commitRootImpl(root, renderPriorityLevel) {
const nextNextEffect = nextEffect.nextEffect;
nextEffect.nextEffect = null;
if (nextEffect.effectTag & Deletion) {
nextEffect.sibling = null;
detachFiberAfterEffects(nextEffect);
}
nextEffect = nextNextEffect;
}
Expand Down Expand Up @@ -2599,7 +2599,7 @@ function flushPassiveEffectsImpl() {
// Remove nextEffect pointer to assist GC
effect.nextEffect = null;
if (effect.effectTag & Deletion) {
effect.sibling = null;
detachFiberAfterEffects(effect);
}
effect = nextNextEffect;
}
Expand Down Expand Up @@ -3718,3 +3718,7 @@ export function act(callback: () => Thenable<mixed>): Thenable<void> {
};
}
}

function detachFiberAfterEffects(fiber: Fiber): void {
fiber.sibling = null;
}

0 comments on commit eb3dc35

Please sign in to comment.