Skip to content

Commit

Permalink
Split flushPassiveUnmountEffects() into two functions
Browse files Browse the repository at this point in the history
One is used for mounted fibers, and one for unmounted subtrees.
  • Loading branch information
Brian Vaughn committed Jul 29, 2020
1 parent c1a1be5 commit ae37c7c
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -2783,15 +2783,12 @@ function flushPassiveUnmountEffects(firstChild: Fiber): void {
primarySubtreeTag !== NoSubtreeTag ||
primaryEffectTag !== NoEffect
) {
flushPassiveUnmountEffects(fiberToDelete);
flushPassiveUnmountEffectsInsideOfDeletedTree(fiberToDelete);
}

// Now that passive effects have been processed, it's safe to detach lingering pointers.
detachFiberAfterEffects(fiberToDelete);
}

// Clear deletions now that passive effects have been procssed.
fiber.deletions = null;
}

const child = fiber.child;
Expand Down Expand Up @@ -2822,6 +2819,39 @@ function flushPassiveUnmountEffects(firstChild: Fiber): void {
}
}

function flushPassiveUnmountEffectsInsideOfDeletedTree(
firstChild: Fiber,
): void {
let fiber = firstChild;
while (fiber !== null) {
const child = fiber.child;
if (child !== null) {
// If any children have passive effects then traverse the subtree.
// Note that this requires checking subtreeTag of the current Fiber,
// rather than the subtreeTag/effectsTag of the first child,
// since that would not cover passive effects in siblings.
const primarySubtreeTag = fiber.subtreeTag & PassiveSubtreeTag;
if (primarySubtreeTag !== NoSubtreeTag) {
flushPassiveUnmountEffectsInsideOfDeletedTree(child);
}
}

switch (fiber.tag) {
case FunctionComponent:
case ForwardRef:
case SimpleMemoComponent:
case Block: {
const primaryEffectTag = fiber.effectTag & Passive;
if (primaryEffectTag !== NoEffect) {
flushPassiveUnmountEffectsImpl(fiber);
}
}
}

fiber = fiber.sibling;
}
}

function flushPassiveUnmountEffectsImpl(fiber: Fiber): void {
const updateQueue: FunctionComponentUpdateQueue | null = (fiber.updateQueue: any);
const lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
Expand Down

0 comments on commit ae37c7c

Please sign in to comment.