@samitouri / QOS-React-2 / commits / d445cee60f

Make temporary `NoStrictPassiveEffects` option work with `useModernStrictMode` (#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`

Tianyu Yao committed Jul 18, 2023 at 11:58 UTC d445cee60f5635e52f15762be9bd8917edac7e93
1 file changed +17 -4
packages/react-reconciler/src/ReactFiberWorkLoop.js
+17 -4
@@ -90,6 +90,7 @@ import {
90 ConcurrentMode,
91 StrictLegacyMode,
92 StrictEffectsMode,
93 + NoStrictPassiveEffectsMode,
94 } from './ReactTypeOfMode';
95 import {
96 HostRoot,
@@ -3538,11 +3539,19 @@ function recursivelyTraverseAndDoubleInvokeEffectsInDEV(
3539 }
3540
3541 // Unconditionally disconnects and connects passive and layout effects.
3541 -function doubleInvokeEffectsOnFiber(root: FiberRoot, fiber: Fiber) {
3542 +function doubleInvokeEffectsOnFiber(
3543 + root: FiberRoot,
3544 + fiber: Fiber,
3545 + shouldDoubleInvokePassiveEffects: boolean = true,
3546 +) {
3547 disappearLayoutEffects(fiber);
3543 - disconnectPassiveEffect(fiber);
3548 + if (shouldDoubleInvokePassiveEffects) {
3549 + disconnectPassiveEffect(fiber);
3550 + }
3551 reappearLayoutEffects(root, fiber.alternate, fiber, false);
3545 - reconnectPassiveEffects(root, fiber, NoLanes, null, false);
3552 + if (shouldDoubleInvokePassiveEffects) {
3553 + reconnectPassiveEffects(root, fiber, NoLanes, null, false);
3554 + }
3555 }
3556
3557 function doubleInvokeEffectsInDEVIfNecessary(
@@ -3559,7 +3568,11 @@ function doubleInvokeEffectsInDEVIfNecessary(
3568 if (fiber.flags & PlacementDEV) {
3569 setCurrentDebugFiberInDEV(fiber);
3570 if (isInStrictMode) {
3562 - doubleInvokeEffectsOnFiber(root, fiber);
3571 + doubleInvokeEffectsOnFiber(
3572 + root,
3573 + fiber,
3574 + (fiber.mode & NoStrictPassiveEffectsMode) === NoMode,
3575 + );
3576 }
3577 resetCurrentDebugFiberInDEV();
3578 } else {