Skip to content

Commit b68f872

Browse files
committed
Add a temporary internal option to disable double useEffect in legacy strict mode (#26914)
<!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please provide enough information so that others can review your pull request. The three fields below are mandatory. Before submitting a pull request, please make sure the following is done: 1. Fork [the repository](https://github.com/facebook/react) and create your branch from `main`. 2. Run `yarn` in the repository root. 3. If you've fixed a bug or added code that should be tested, add tests! 4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch TestName` is helpful in development. 5. Run `yarn test --prod` to test in the production environment. It supports the same options as `yarn test`. 6. If you need a debugger, run `yarn test --debug --watch TestName`, open `chrome://inspect`, and press "Inspect". 7. Format your code with [prettier](https://github.com/prettier/prettier) (`yarn prettier`). 8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only check changed files. 9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`). 10. If you haven't already, complete the CLA. Learn more about contributing: https://reactjs.org/docs/how-to-contribute.html --> ## Summary <!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? --> We are upgrading React 17 codebase to React18, and `StrictMode` has been great for surfacing potential production bugs on React18 for class components. There are non-trivial number of test failures caused by double `useEffect` in StrictMode. To prioritize surfacing and fixing issues that will break in production now, we need a flag to turn off double `useEffect` for now in StrictMode temporarily. This is a Meta-only hack for rolling out `createRoot` and we will fast follow to remove it and use full strict mode. ## How did you test this change? <!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes the user interface. How exactly did you verify that your PR solves the issue you wanted to solve? If you leave this empty, your PR will very likely be closed. --> jest DiffTrain build for commit 254cbdb.
1 parent 8218aaa commit b68f872

File tree

9 files changed

+50
-17
lines changed

9 files changed

+50
-17
lines changed

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-dev.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<686a43f16ce095ac9828d46ee7e914ff>>
10+
* @generated SignedSource<<8b35d681c01d550a6b69db76a1733d08>>
1111
*/
1212

1313
'use strict';
@@ -1025,6 +1025,9 @@ var StrictEffectsMode =
10251025
var ConcurrentUpdatesByDefaultMode =
10261026
/* */
10271027
32;
1028+
var NoStrictPassiveEffectsMode =
1029+
/* */
1030+
64;
10281031

10291032
// TODO: This is pretty well supported by browsers. Maybe we can drop it.
10301033
var clz32 = Math.clz32 ? Math.clz32 : clz32Fallback; // Count leading zeros.
@@ -7792,7 +7795,10 @@ function updateEffectImpl(fiberFlags, hookFlags, create, deps) {
77927795
}
77937796

77947797
function mountEffect(create, deps) {
7795-
if ((currentlyRenderingFiber$1.mode & StrictEffectsMode) !== NoMode) {
7798+
if (
7799+
(currentlyRenderingFiber$1.mode & StrictEffectsMode) !== NoMode &&
7800+
(currentlyRenderingFiber$1.mode & NoStrictPassiveEffectsMode) === NoMode
7801+
) {
77967802
mountEffectImpl(
77977803
MountPassiveDev | Passive$1 | PassiveStatic,
77987804
Passive,
@@ -23763,6 +23769,11 @@ function createFiberFromSuspenseList(pendingProps, mode, lanes, key) {
2376323769
return fiber;
2376423770
}
2376523771
function createFiberFromOffscreen(pendingProps, mode, lanes, key) {
23772+
{
23773+
// StrictMode in Offscreen should always run double passive effects
23774+
mode &= ~NoStrictPassiveEffectsMode;
23775+
}
23776+
2376623777
var fiber = createFiber(OffscreenComponent, pendingProps, key, mode);
2376723778
fiber.elementType = REACT_OFFSCREEN_TYPE;
2376823779
fiber.lanes = lanes;
@@ -23923,7 +23934,7 @@ function createFiberRoot(
2392323934
return root;
2392423935
}
2392523936

23926-
var ReactVersion = "18.3.0-canary-e3fb7c1de-20230621";
23937+
var ReactVersion = "18.3.0-canary-254cbdbd6-20230621";
2392723938

2392823939
// Might add PROFILE later.
2392923940

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-prod.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8617,7 +8617,7 @@ var devToolsConfig$jscomp$inline_1031 = {
86178617
throw Error("TestRenderer does not support findFiberByHostInstance()");
86188618
},
86198619
bundleType: 0,
8620-
version: "18.3.0-canary-e3fb7c1de-20230621",
8620+
version: "18.3.0-canary-254cbdbd6-20230621",
86218621
rendererPackageName: "react-test-renderer"
86228622
};
86238623
var internals$jscomp$inline_1230 = {
@@ -8648,7 +8648,7 @@ var internals$jscomp$inline_1230 = {
86488648
scheduleRoot: null,
86498649
setRefreshHandler: null,
86508650
getCurrentFiber: null,
8651-
reconcilerVersion: "18.3.0-canary-e3fb7c1de-20230621"
8651+
reconcilerVersion: "18.3.0-canary-254cbdbd6-20230621"
86528652
};
86538653
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
86548654
var hook$jscomp$inline_1231 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-profiling.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9043,7 +9043,7 @@ var devToolsConfig$jscomp$inline_1073 = {
90439043
throw Error("TestRenderer does not support findFiberByHostInstance()");
90449044
},
90459045
bundleType: 0,
9046-
version: "18.3.0-canary-e3fb7c1de-20230621",
9046+
version: "18.3.0-canary-254cbdbd6-20230621",
90479047
rendererPackageName: "react-test-renderer"
90489048
};
90499049
var internals$jscomp$inline_1271 = {
@@ -9074,7 +9074,7 @@ var internals$jscomp$inline_1271 = {
90749074
scheduleRoot: null,
90759075
setRefreshHandler: null,
90769076
getCurrentFiber: null,
9077-
reconcilerVersion: "18.3.0-canary-e3fb7c1de-20230621"
9077+
reconcilerVersion: "18.3.0-canary-254cbdbd6-20230621"
90789078
};
90799079
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
90809080
var hook$jscomp$inline_1272 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (
2727
}
2828
"use strict";
2929

30-
var ReactVersion = "18.3.0-canary-e3fb7c1de-20230621";
30+
var ReactVersion = "18.3.0-canary-254cbdbd6-20230621";
3131

3232
// ATTENTION
3333
// When adding new symbols to this file,

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-prod.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,4 +642,4 @@ exports.useSyncExternalStore = function (
642642
);
643643
};
644644
exports.useTransition = useTransition;
645-
exports.version = "18.3.0-canary-e3fb7c1de-20230621";
645+
exports.version = "18.3.0-canary-254cbdbd6-20230621";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-profiling.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ exports.useSyncExternalStore = function (
645645
);
646646
};
647647
exports.useTransition = useTransition;
648-
exports.version = "18.3.0-canary-e3fb7c1de-20230621";
648+
exports.version = "18.3.0-canary-254cbdbd6-20230621";
649649

650650
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
651651
if (
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e3fb7c1de1ed375e32397b3502a30b8ae4c2db9f
1+
254cbdbd6d851a30bf3b649a6cb7c52786766fa4

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<c969a4144be0d81d2e4ff40ed03beb08>>
10+
* @generated SignedSource<<514b18ed9abf66bd67c35f8d3892be26>>
1111
*/
1212

1313
'use strict';
@@ -3876,6 +3876,9 @@ var StrictEffectsMode =
38763876
var ConcurrentUpdatesByDefaultMode =
38773877
/* */
38783878
32;
3879+
var NoStrictPassiveEffectsMode =
3880+
/* */
3881+
64;
38793882

38803883
// TODO: This is pretty well supported by browsers. Maybe we can drop it.
38813884
var clz32 = Math.clz32 ? Math.clz32 : clz32Fallback; // Count leading zeros.
@@ -11956,7 +11959,10 @@ function updateEffectImpl(fiberFlags, hookFlags, create, deps) {
1195611959
}
1195711960

1195811961
function mountEffect(create, deps) {
11959-
if ((currentlyRenderingFiber$1.mode & StrictEffectsMode) !== NoMode) {
11962+
if (
11963+
(currentlyRenderingFiber$1.mode & StrictEffectsMode) !== NoMode &&
11964+
(currentlyRenderingFiber$1.mode & NoStrictPassiveEffectsMode) === NoMode
11965+
) {
1196011966
mountEffectImpl(
1196111967
MountPassiveDev | Passive$1 | PassiveStatic,
1196211968
Passive,
@@ -27019,6 +27025,11 @@ function createFiberFromSuspenseList(pendingProps, mode, lanes, key) {
2701927025
return fiber;
2702027026
}
2702127027
function createFiberFromOffscreen(pendingProps, mode, lanes, key) {
27028+
{
27029+
// StrictMode in Offscreen should always run double passive effects
27030+
mode &= ~NoStrictPassiveEffectsMode;
27031+
}
27032+
2702227033
var fiber = createFiber(OffscreenComponent, pendingProps, key, mode);
2702327034
fiber.elementType = REACT_OFFSCREEN_TYPE;
2702427035
fiber.lanes = lanes;
@@ -27238,7 +27249,7 @@ function createFiberRoot(
2723827249
return root;
2723927250
}
2724027251

27241-
var ReactVersion = "18.3.0-canary-cfb11465";
27252+
var ReactVersion = "18.3.0-canary-8ff97f72";
2724227253

2724327254
function createPortal$1(
2724427255
children,

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-dev.fb.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<4525ca8b79fb39404269c7e945572f4a>>
10+
* @generated SignedSource<<14c435eed21e626d0548f1265b3a2ab8>>
1111
*/
1212

1313
'use strict';
@@ -4737,6 +4737,9 @@ var StrictEffectsMode =
47374737
var ConcurrentUpdatesByDefaultMode =
47384738
/* */
47394739
32;
4740+
var NoStrictPassiveEffectsMode =
4741+
/* */
4742+
64;
47404743

47414744
// TODO: This is pretty well supported by browsers. Maybe we can drop it.
47424745
var clz32 = Math.clz32 ? Math.clz32 : clz32Fallback; // Count leading zeros.
@@ -12273,7 +12276,10 @@ function updateEffectImpl(fiberFlags, hookFlags, create, deps) {
1227312276
}
1227412277

1227512278
function mountEffect(create, deps) {
12276-
if ((currentlyRenderingFiber$1.mode & StrictEffectsMode) !== NoMode) {
12279+
if (
12280+
(currentlyRenderingFiber$1.mode & StrictEffectsMode) !== NoMode &&
12281+
(currentlyRenderingFiber$1.mode & NoStrictPassiveEffectsMode) === NoMode
12282+
) {
1227712283
mountEffectImpl(
1227812284
MountPassiveDev | Passive$1 | PassiveStatic,
1227912285
Passive,
@@ -27533,6 +27539,11 @@ function createFiberFromSuspenseList(pendingProps, mode, lanes, key) {
2753327539
return fiber;
2753427540
}
2753527541
function createFiberFromOffscreen(pendingProps, mode, lanes, key) {
27542+
{
27543+
// StrictMode in Offscreen should always run double passive effects
27544+
mode &= ~NoStrictPassiveEffectsMode;
27545+
}
27546+
2753627547
var fiber = createFiber(OffscreenComponent, pendingProps, key, mode);
2753727548
fiber.elementType = REACT_OFFSCREEN_TYPE;
2753827549
fiber.lanes = lanes;
@@ -27752,7 +27763,7 @@ function createFiberRoot(
2775227763
return root;
2775327764
}
2775427765

27755-
var ReactVersion = "18.3.0-canary-225345a1";
27766+
var ReactVersion = "18.3.0-canary-a48d7fee";
2775627767

2775727768
function createPortal$1(
2775827769
children,

0 commit comments

Comments
 (0)