Skip to content

Commit

Permalink
Refactor double invoking logic into single if/else statement
Browse files Browse the repository at this point in the history
  • Loading branch information
sammy-SC committed Sep 9, 2022
1 parent fc298f5 commit 9c2f26b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
26 changes: 14 additions & 12 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -3186,19 +3186,21 @@ function doubleInvokeEffectsInDEV(
const isStrictModeFiber = fiber.type === REACT_STRICT_MODE_TYPE;
const isInStrictMode = parentIsInStrictMode || isStrictModeFiber;

if (fiber.flags & PlacementDEV || fiber.tag === OffscreenComponent) {
if (
isInStrictMode &&
// Check for newly mounted trees
(fiber.flags & PlacementDEV ||
// Check for trees that are going from hidden -> visible
(fiber.tag === OffscreenComponent &&
fiber.flags & Visibility &&
fiber.memoizedState === null))
) {
// Double invoke all the effects in this tree
setCurrentDebugFiberInDEV(fiber);
const isNotOffscreen = fiber.tag !== OffscreenComponent;
// Checks if Offscreen is being revealed. For all other components, evaluates to true.
const hasOffscreenBecomeVisible =
isNotOffscreen ||
(fiber.flags & Visibility && fiber.memoizedState === null);
if (isInStrictMode && hasOffscreenBecomeVisible) {
disappearLayoutEffects(fiber);
disconnectPassiveEffect(fiber);
reappearLayoutEffects(root, fiber.alternate, fiber, false);
reconnectPassiveEffects(root, fiber, NoLanes, null, false);
}
disappearLayoutEffects(fiber);
disconnectPassiveEffect(fiber);
reappearLayoutEffects(root, fiber.alternate, fiber, false);
reconnectPassiveEffects(root, fiber, NoLanes, null, false);
resetCurrentDebugFiberInDEV();
} else {
recursivelyTraverseAndDoubleInvokeEffectsInDEV(root, fiber, isInStrictMode);
Expand Down
26 changes: 14 additions & 12 deletions packages/react-reconciler/src/ReactFiberWorkLoop.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -3186,19 +3186,21 @@ function doubleInvokeEffectsInDEV(
const isStrictModeFiber = fiber.type === REACT_STRICT_MODE_TYPE;
const isInStrictMode = parentIsInStrictMode || isStrictModeFiber;

if (fiber.flags & PlacementDEV || fiber.tag === OffscreenComponent) {
if (
isInStrictMode &&
// Check for newly mounted trees
(fiber.flags & PlacementDEV ||
// Check for trees that are going from hidden -> visible
(fiber.tag === OffscreenComponent &&
fiber.flags & Visibility &&
fiber.memoizedState === null))
) {
// Double invoke all the effects in this tree
setCurrentDebugFiberInDEV(fiber);
const isNotOffscreen = fiber.tag !== OffscreenComponent;
// Checks if Offscreen is being revealed. For all other components, evaluates to true.
const hasOffscreenBecomeVisible =
isNotOffscreen ||
(fiber.flags & Visibility && fiber.memoizedState === null);
if (isInStrictMode && hasOffscreenBecomeVisible) {
disappearLayoutEffects(fiber);
disconnectPassiveEffect(fiber);
reappearLayoutEffects(root, fiber.alternate, fiber, false);
reconnectPassiveEffects(root, fiber, NoLanes, null, false);
}
disappearLayoutEffects(fiber);
disconnectPassiveEffect(fiber);
reappearLayoutEffects(root, fiber.alternate, fiber, false);
reconnectPassiveEffects(root, fiber, NoLanes, null, false);
resetCurrentDebugFiberInDEV();
} else {
recursivelyTraverseAndDoubleInvokeEffectsInDEV(root, fiber, isInStrictMode);
Expand Down

0 comments on commit 9c2f26b

Please sign in to comment.