@samitouri / QOS-React-2 / commits / 948fad357b

Improve detachFiber (#18536)

Dominic Gannaway committed Apr 8, 2020 at 01:45 UTC 948fad357b41002f7e9139211464470b3c0462e8
1 file changed +16 -16
packages/react-reconciler/src/ReactFiberCommitWork.js
+16 -16
@@ -1097,27 +1097,23 @@ function commitNestedUnmounts(
1097 }
1098 }
1099
1100 -function detachFiber(current: Fiber) {
1101 - const alternate = current.alternate;
1100 +function detachFiber(fiber: Fiber) {
1101 // Cut off the return pointers to disconnect it from the tree. Ideally, we
1102 // should clear the child pointer of the parent alternate to let this
1103 // get GC:ed but we don't know which for sure which parent is the current
1104 // one so we'll settle for GC:ing the subtree of this child. This child
1105 // itself will be GC:ed when the parent updates the next time.
1107 - current.return = null;
1108 - current.child = null;
1109 - current.memoizedState = null;
1110 - current.updateQueue = null;
1111 - current.dependencies = null;
1112 - current.alternate = null;
1113 - current.firstEffect = null;
1114 - current.lastEffect = null;
1115 - current.pendingProps = null;
1116 - current.memoizedProps = null;
1117 - current.stateNode = null;
1118 - if (alternate !== null) {
1119 - detachFiber(alternate);
1120 - }
1106 + fiber.return = null;
1107 + fiber.child = null;
1108 + fiber.memoizedState = null;
1109 + fiber.updateQueue = null;
1110 + fiber.dependencies = null;
1111 + fiber.alternate = null;
1112 + fiber.firstEffect = null;
1113 + fiber.lastEffect = null;
1114 + fiber.pendingProps = null;
1115 + fiber.memoizedProps = null;
1116 + fiber.stateNode = null;
1117 }
1118
1119 function emptyPortalContainer(current: Fiber) {
@@ -1485,7 +1481,11 @@ function commitDeletion(
1481 // Detach refs and call componentWillUnmount() on the whole subtree.
1482 commitNestedUnmounts(finishedRoot, current, renderPriorityLevel);
1483 }
1484 + const alternate = current.alternate;
1485 detachFiber(current);
1486 + if (alternate !== null) {
1487 + detachFiber(alternate);
1488 + }
1489 }
1490
1491 function commitWork(current: Fiber | null, finishedWork: Fiber): void {