mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
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 https://github.com/facebook/react/commit/254cbdbd6d851a30bf3b649a6cb7c52786766fa4.
This commit is contained in:
+14
-3
@@ -7,7 +7,7 @@
|
||||
* @noflow
|
||||
* @nolint
|
||||
* @preventMunge
|
||||
* @generated SignedSource<<686a43f16ce095ac9828d46ee7e914ff>>
|
||||
* @generated SignedSource<<8b35d681c01d550a6b69db76a1733d08>>
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
@@ -1025,6 +1025,9 @@ var StrictEffectsMode =
|
||||
var ConcurrentUpdatesByDefaultMode =
|
||||
/* */
|
||||
32;
|
||||
var NoStrictPassiveEffectsMode =
|
||||
/* */
|
||||
64;
|
||||
|
||||
// TODO: This is pretty well supported by browsers. Maybe we can drop it.
|
||||
var clz32 = Math.clz32 ? Math.clz32 : clz32Fallback; // Count leading zeros.
|
||||
@@ -7792,7 +7795,10 @@ function updateEffectImpl(fiberFlags, hookFlags, create, deps) {
|
||||
}
|
||||
|
||||
function mountEffect(create, deps) {
|
||||
if ((currentlyRenderingFiber$1.mode & StrictEffectsMode) !== NoMode) {
|
||||
if (
|
||||
(currentlyRenderingFiber$1.mode & StrictEffectsMode) !== NoMode &&
|
||||
(currentlyRenderingFiber$1.mode & NoStrictPassiveEffectsMode) === NoMode
|
||||
) {
|
||||
mountEffectImpl(
|
||||
MountPassiveDev | Passive$1 | PassiveStatic,
|
||||
Passive,
|
||||
@@ -23763,6 +23769,11 @@ function createFiberFromSuspenseList(pendingProps, mode, lanes, key) {
|
||||
return fiber;
|
||||
}
|
||||
function createFiberFromOffscreen(pendingProps, mode, lanes, key) {
|
||||
{
|
||||
// StrictMode in Offscreen should always run double passive effects
|
||||
mode &= ~NoStrictPassiveEffectsMode;
|
||||
}
|
||||
|
||||
var fiber = createFiber(OffscreenComponent, pendingProps, key, mode);
|
||||
fiber.elementType = REACT_OFFSCREEN_TYPE;
|
||||
fiber.lanes = lanes;
|
||||
@@ -23923,7 +23934,7 @@ function createFiberRoot(
|
||||
return root;
|
||||
}
|
||||
|
||||
var ReactVersion = "18.3.0-canary-e3fb7c1de-20230621";
|
||||
var ReactVersion = "18.3.0-canary-254cbdbd6-20230621";
|
||||
|
||||
// Might add PROFILE later.
|
||||
|
||||
|
||||
+2
-2
@@ -8617,7 +8617,7 @@ var devToolsConfig$jscomp$inline_1031 = {
|
||||
throw Error("TestRenderer does not support findFiberByHostInstance()");
|
||||
},
|
||||
bundleType: 0,
|
||||
version: "18.3.0-canary-e3fb7c1de-20230621",
|
||||
version: "18.3.0-canary-254cbdbd6-20230621",
|
||||
rendererPackageName: "react-test-renderer"
|
||||
};
|
||||
var internals$jscomp$inline_1230 = {
|
||||
@@ -8648,7 +8648,7 @@ var internals$jscomp$inline_1230 = {
|
||||
scheduleRoot: null,
|
||||
setRefreshHandler: null,
|
||||
getCurrentFiber: null,
|
||||
reconcilerVersion: "18.3.0-canary-e3fb7c1de-20230621"
|
||||
reconcilerVersion: "18.3.0-canary-254cbdbd6-20230621"
|
||||
};
|
||||
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
|
||||
var hook$jscomp$inline_1231 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
|
||||
|
||||
+2
-2
@@ -9043,7 +9043,7 @@ var devToolsConfig$jscomp$inline_1073 = {
|
||||
throw Error("TestRenderer does not support findFiberByHostInstance()");
|
||||
},
|
||||
bundleType: 0,
|
||||
version: "18.3.0-canary-e3fb7c1de-20230621",
|
||||
version: "18.3.0-canary-254cbdbd6-20230621",
|
||||
rendererPackageName: "react-test-renderer"
|
||||
};
|
||||
var internals$jscomp$inline_1271 = {
|
||||
@@ -9074,7 +9074,7 @@ var internals$jscomp$inline_1271 = {
|
||||
scheduleRoot: null,
|
||||
setRefreshHandler: null,
|
||||
getCurrentFiber: null,
|
||||
reconcilerVersion: "18.3.0-canary-e3fb7c1de-20230621"
|
||||
reconcilerVersion: "18.3.0-canary-254cbdbd6-20230621"
|
||||
};
|
||||
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
|
||||
var hook$jscomp$inline_1272 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ if (
|
||||
}
|
||||
"use strict";
|
||||
|
||||
var ReactVersion = "18.3.0-canary-e3fb7c1de-20230621";
|
||||
var ReactVersion = "18.3.0-canary-254cbdbd6-20230621";
|
||||
|
||||
// ATTENTION
|
||||
// When adding new symbols to this file,
|
||||
|
||||
+1
-1
@@ -642,4 +642,4 @@ exports.useSyncExternalStore = function (
|
||||
);
|
||||
};
|
||||
exports.useTransition = useTransition;
|
||||
exports.version = "18.3.0-canary-e3fb7c1de-20230621";
|
||||
exports.version = "18.3.0-canary-254cbdbd6-20230621";
|
||||
|
||||
+1
-1
@@ -645,7 +645,7 @@ exports.useSyncExternalStore = function (
|
||||
);
|
||||
};
|
||||
exports.useTransition = useTransition;
|
||||
exports.version = "18.3.0-canary-e3fb7c1de-20230621";
|
||||
exports.version = "18.3.0-canary-254cbdbd6-20230621";
|
||||
|
||||
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
|
||||
if (
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
e3fb7c1de1ed375e32397b3502a30b8ae4c2db9f
|
||||
254cbdbd6d851a30bf3b649a6cb7c52786766fa4
|
||||
|
||||
+14
-3
@@ -7,7 +7,7 @@
|
||||
* @noflow
|
||||
* @nolint
|
||||
* @preventMunge
|
||||
* @generated SignedSource<<c969a4144be0d81d2e4ff40ed03beb08>>
|
||||
* @generated SignedSource<<514b18ed9abf66bd67c35f8d3892be26>>
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
@@ -3876,6 +3876,9 @@ var StrictEffectsMode =
|
||||
var ConcurrentUpdatesByDefaultMode =
|
||||
/* */
|
||||
32;
|
||||
var NoStrictPassiveEffectsMode =
|
||||
/* */
|
||||
64;
|
||||
|
||||
// TODO: This is pretty well supported by browsers. Maybe we can drop it.
|
||||
var clz32 = Math.clz32 ? Math.clz32 : clz32Fallback; // Count leading zeros.
|
||||
@@ -11956,7 +11959,10 @@ function updateEffectImpl(fiberFlags, hookFlags, create, deps) {
|
||||
}
|
||||
|
||||
function mountEffect(create, deps) {
|
||||
if ((currentlyRenderingFiber$1.mode & StrictEffectsMode) !== NoMode) {
|
||||
if (
|
||||
(currentlyRenderingFiber$1.mode & StrictEffectsMode) !== NoMode &&
|
||||
(currentlyRenderingFiber$1.mode & NoStrictPassiveEffectsMode) === NoMode
|
||||
) {
|
||||
mountEffectImpl(
|
||||
MountPassiveDev | Passive$1 | PassiveStatic,
|
||||
Passive,
|
||||
@@ -27019,6 +27025,11 @@ function createFiberFromSuspenseList(pendingProps, mode, lanes, key) {
|
||||
return fiber;
|
||||
}
|
||||
function createFiberFromOffscreen(pendingProps, mode, lanes, key) {
|
||||
{
|
||||
// StrictMode in Offscreen should always run double passive effects
|
||||
mode &= ~NoStrictPassiveEffectsMode;
|
||||
}
|
||||
|
||||
var fiber = createFiber(OffscreenComponent, pendingProps, key, mode);
|
||||
fiber.elementType = REACT_OFFSCREEN_TYPE;
|
||||
fiber.lanes = lanes;
|
||||
@@ -27238,7 +27249,7 @@ function createFiberRoot(
|
||||
return root;
|
||||
}
|
||||
|
||||
var ReactVersion = "18.3.0-canary-cfb11465";
|
||||
var ReactVersion = "18.3.0-canary-8ff97f72";
|
||||
|
||||
function createPortal$1(
|
||||
children,
|
||||
|
||||
+14
-3
@@ -7,7 +7,7 @@
|
||||
* @noflow
|
||||
* @nolint
|
||||
* @preventMunge
|
||||
* @generated SignedSource<<4525ca8b79fb39404269c7e945572f4a>>
|
||||
* @generated SignedSource<<14c435eed21e626d0548f1265b3a2ab8>>
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
@@ -4737,6 +4737,9 @@ var StrictEffectsMode =
|
||||
var ConcurrentUpdatesByDefaultMode =
|
||||
/* */
|
||||
32;
|
||||
var NoStrictPassiveEffectsMode =
|
||||
/* */
|
||||
64;
|
||||
|
||||
// TODO: This is pretty well supported by browsers. Maybe we can drop it.
|
||||
var clz32 = Math.clz32 ? Math.clz32 : clz32Fallback; // Count leading zeros.
|
||||
@@ -12273,7 +12276,10 @@ function updateEffectImpl(fiberFlags, hookFlags, create, deps) {
|
||||
}
|
||||
|
||||
function mountEffect(create, deps) {
|
||||
if ((currentlyRenderingFiber$1.mode & StrictEffectsMode) !== NoMode) {
|
||||
if (
|
||||
(currentlyRenderingFiber$1.mode & StrictEffectsMode) !== NoMode &&
|
||||
(currentlyRenderingFiber$1.mode & NoStrictPassiveEffectsMode) === NoMode
|
||||
) {
|
||||
mountEffectImpl(
|
||||
MountPassiveDev | Passive$1 | PassiveStatic,
|
||||
Passive,
|
||||
@@ -27533,6 +27539,11 @@ function createFiberFromSuspenseList(pendingProps, mode, lanes, key) {
|
||||
return fiber;
|
||||
}
|
||||
function createFiberFromOffscreen(pendingProps, mode, lanes, key) {
|
||||
{
|
||||
// StrictMode in Offscreen should always run double passive effects
|
||||
mode &= ~NoStrictPassiveEffectsMode;
|
||||
}
|
||||
|
||||
var fiber = createFiber(OffscreenComponent, pendingProps, key, mode);
|
||||
fiber.elementType = REACT_OFFSCREEN_TYPE;
|
||||
fiber.lanes = lanes;
|
||||
@@ -27752,7 +27763,7 @@ function createFiberRoot(
|
||||
return root;
|
||||
}
|
||||
|
||||
var ReactVersion = "18.3.0-canary-225345a1";
|
||||
var ReactVersion = "18.3.0-canary-a48d7fee";
|
||||
|
||||
function createPortal$1(
|
||||
children,
|
||||
|
||||
Reference in New Issue
Block a user