Skip to content

Commit

Permalink
https://github.com/facebook/react/pull/15157
Browse files Browse the repository at this point in the history
  • Loading branch information
paulshen committed Apr 11, 2019
1 parent 487f4bf commit 11bf326
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
18 changes: 10 additions & 8 deletions packages/react-reconciler/src/ReactFiberCommitWork.js
Expand Up @@ -742,6 +742,12 @@ function commitUnmount(current: Fiber): void {
return;
}
}

// Remove reference for GC
current.stateNode = null;
if (current.alternate != null) {
current.alternate.stateNode = null;
}
}

function commitNestedUnmounts(root: Fiber): void {
Expand Down Expand Up @@ -1038,19 +1044,15 @@ function unmountHostComponents(current): void {
}

if (node.tag === HostComponent || node.tag === HostText) {
// Save stateNode reference so commitUnmount can clear it.
const stateNode: Instance | TextInstance = node.stateNode;
commitNestedUnmounts(node);
// After all the children have unmounted, it is now safe to remove the
// node from the tree.
if (currentParentIsContainer) {
removeChildFromContainer(
((currentParent: any): Container),
(node.stateNode: Instance | TextInstance),
);
removeChildFromContainer(((currentParent: any): Container), stateNode);
} else {
removeChild(
((currentParent: any): Instance),
(node.stateNode: Instance | TextInstance),
);
removeChild(((currentParent: any): Instance), stateNode);
}
// Don't visit children because we already visited them.
} else if (
Expand Down
15 changes: 14 additions & 1 deletion packages/react-reconciler/src/ReactFiberScheduler.js
Expand Up @@ -696,7 +696,10 @@ function commitRoot(root: FiberRoot, finishedWork: Fiber): void {
captureCommitPhaseError(nextEffect, error);
// Clean-up
if (nextEffect !== null) {
nextEffect = nextEffect.nextEffect;
const nextNextEffect = nextEffect.nextEffect;
// Remove nextEffect pointer to assist GC
nextEffect.nextEffect = null;
nextEffect = nextNextEffect;
}
}
}
Expand Down Expand Up @@ -811,6 +814,16 @@ function commitRoot(root: FiberRoot, finishedWork: Fiber): void {
return schedulePassiveEffects(callback);
});
passiveEffectCallback = callback;
} else {
// We are done with the effect chain at this point so let's clear the
// nextEffect pointers to assist with GC. If we have passive effects, we'll
// clear this in commitPassiveEffects.
nextEffect = firstEffect;
while (nextEffect !== null) {
const nextNextEffect = nextEffect.nextEffect;
nextEffect.nextEffect = null;
nextEffect = nextNextEffect;
}
}

isCommitting = false;
Expand Down

0 comments on commit 11bf326

Please sign in to comment.