Skip to content

Commit

Permalink
Make temporary NoStrictPassiveEffects option work with `useModernSt…
Browse files Browse the repository at this point in the history
…rictMode` (#27105)

## Summary
Since we are enabling `useModernStrictMode` flag internally, to make
sure the internal testing of half StrictMode doesn't suddenly break,
this PR makes sure it also works with `useModernStrictMode` true.


## Test plan:
Manually set `useModernStrictMode` to true.
`yarn test ReactOffscreenStrictMode-test -r=www-modern --env=development
--variant=true`
`yarn test ReactStrictMode-test.internal -r=www-modern --env=development
--variant=true`
  • Loading branch information
tyao1 authored Jul 18, 2023
1 parent 9f4fbec commit d445cee
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions packages/react-reconciler/src/ReactFiberWorkLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import {
ConcurrentMode,
StrictLegacyMode,
StrictEffectsMode,
NoStrictPassiveEffectsMode,
} from './ReactTypeOfMode';
import {
HostRoot,
Expand Down Expand Up @@ -3538,11 +3539,19 @@ function recursivelyTraverseAndDoubleInvokeEffectsInDEV(
}

// Unconditionally disconnects and connects passive and layout effects.
function doubleInvokeEffectsOnFiber(root: FiberRoot, fiber: Fiber) {
function doubleInvokeEffectsOnFiber(
root: FiberRoot,
fiber: Fiber,
shouldDoubleInvokePassiveEffects: boolean = true,
) {
disappearLayoutEffects(fiber);
disconnectPassiveEffect(fiber);
if (shouldDoubleInvokePassiveEffects) {
disconnectPassiveEffect(fiber);
}
reappearLayoutEffects(root, fiber.alternate, fiber, false);
reconnectPassiveEffects(root, fiber, NoLanes, null, false);
if (shouldDoubleInvokePassiveEffects) {
reconnectPassiveEffects(root, fiber, NoLanes, null, false);
}
}

function doubleInvokeEffectsInDEVIfNecessary(
Expand All @@ -3559,7 +3568,11 @@ function doubleInvokeEffectsInDEVIfNecessary(
if (fiber.flags & PlacementDEV) {
setCurrentDebugFiberInDEV(fiber);
if (isInStrictMode) {
doubleInvokeEffectsOnFiber(root, fiber);
doubleInvokeEffectsOnFiber(
root,
fiber,
(fiber.mode & NoStrictPassiveEffectsMode) === NoMode,
);
}
resetCurrentDebugFiberInDEV();
} else {
Expand Down

0 comments on commit d445cee

Please sign in to comment.