Skip to content

Commit

Permalink
Add a temporary internal option to disable double useEffect in legacy…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
tyao1 committed Jun 21, 2023
1 parent 8218aaa commit b68f872
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<686a43f16ce095ac9828d46ee7e914ff>>
* @generated SignedSource<<8b35d681c01d550a6b69db76a1733d08>>
*/

'use strict';
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
e3fb7c1de1ed375e32397b3502a30b8ae4c2db9f
254cbdbd6d851a30bf3b649a6cb7c52786766fa4
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<c969a4144be0d81d2e4ff40ed03beb08>>
* @generated SignedSource<<514b18ed9abf66bd67c35f8d3892be26>>
*/

'use strict';
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<4525ca8b79fb39404269c7e945572f4a>>
* @generated SignedSource<<14c435eed21e626d0548f1265b3a2ab8>>
*/

'use strict';
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit b68f872

Please sign in to comment.