From f5528063eecf505e2d49a38b5f95ca256289daad Mon Sep 17 00:00:00 2001 From: Ricky Hanlon Date: Mon, 29 Jan 2024 17:09:51 -0500 Subject: [PATCH 1/3] Move modern strict to experimental --- .../src/__tests__/ReactStrictMode-test.js | 32 +++++++++++++------ packages/shared/ReactFeatureFlags.js | 2 +- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/packages/react/src/__tests__/ReactStrictMode-test.js b/packages/react/src/__tests__/ReactStrictMode-test.js index 4ccc9a2687175..1834a7d0f30e6 100644 --- a/packages/react/src/__tests__/ReactStrictMode-test.js +++ b/packages/react/src/__tests__/ReactStrictMode-test.js @@ -116,15 +116,29 @@ describe('ReactStrictMode', () => { container, ); - expect(log).toEqual([ - 'constructor', - 'constructor', - 'getDerivedStateFromProps', - 'getDerivedStateFromProps', - 'render', - 'render', - 'componentDidMount', - ]); + if (gate(flags => flags.useModernStrictMode)) { + expect(log).toEqual([ + 'constructor', + 'constructor', + 'getDerivedStateFromProps', + 'getDerivedStateFromProps', + 'render', + 'render', + 'componentDidMount', + 'componentWillUnmount', + 'componentDidMount', + ]); + } else { + expect(log).toEqual([ + 'constructor', + 'constructor', + 'getDerivedStateFromProps', + 'getDerivedStateFromProps', + 'render', + 'render', + 'componentDidMount', + ]); + } log = []; shouldComponentUpdate = true; diff --git a/packages/shared/ReactFeatureFlags.js b/packages/shared/ReactFeatureFlags.js index 67862a4f14288..3d8a7cf563bc8 100644 --- a/packages/shared/ReactFeatureFlags.js +++ b/packages/shared/ReactFeatureFlags.js @@ -147,7 +147,7 @@ export const disableJavaScriptURLs = false; // Modern behaviour aligns more with what components // components will encounter in production, especially when used With . // TODO: clean up legacy once tests pass WWW. -export const useModernStrictMode = false; +export const useModernStrictMode = __NEXT_MAJOR__; // Not ready to break experimental yet. // Remove IE and MsApp specific workarounds for innerHTML From a92a3acedbea4b8933d1cb26bfbd77f8226ed727 Mon Sep 17 00:00:00 2001 From: Ricky Hanlon Date: Fri, 9 Feb 2024 15:58:49 -0500 Subject: [PATCH 2/3] Turn off strict effects in legacy roots with useModernStrictMode --- packages/react-reconciler/src/ReactFiberWorkLoop.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.js b/packages/react-reconciler/src/ReactFiberWorkLoop.js index 5fafd8de5c903..d045fa08496e1 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.js @@ -3792,12 +3792,9 @@ function commitDoubleInvokeEffectsInDEV( hasPassiveEffects: boolean, ) { if (__DEV__) { - if (useModernStrictMode) { + if (useModernStrictMode && root.tag !== LegacyRoot) { let doubleInvokeEffects = true; - if (root.tag === LegacyRoot && !(root.current.mode & StrictLegacyMode)) { - doubleInvokeEffects = false; - } if ( root.tag === ConcurrentRoot && !(root.current.mode & (StrictLegacyMode | StrictEffectsMode)) From 4afefce3f6c5fe5eb6e965ae898f2cd5df39ee46 Mon Sep 17 00:00:00 2001 From: Ricky Hanlon Date: Fri, 9 Feb 2024 16:45:10 -0500 Subject: [PATCH 3/3] Legacy mode never double invokes effects --- .../src/__tests__/ReactStrictMode-test.js | 32 ++++++------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/packages/react/src/__tests__/ReactStrictMode-test.js b/packages/react/src/__tests__/ReactStrictMode-test.js index 1834a7d0f30e6..4ccc9a2687175 100644 --- a/packages/react/src/__tests__/ReactStrictMode-test.js +++ b/packages/react/src/__tests__/ReactStrictMode-test.js @@ -116,29 +116,15 @@ describe('ReactStrictMode', () => { container, ); - if (gate(flags => flags.useModernStrictMode)) { - expect(log).toEqual([ - 'constructor', - 'constructor', - 'getDerivedStateFromProps', - 'getDerivedStateFromProps', - 'render', - 'render', - 'componentDidMount', - 'componentWillUnmount', - 'componentDidMount', - ]); - } else { - expect(log).toEqual([ - 'constructor', - 'constructor', - 'getDerivedStateFromProps', - 'getDerivedStateFromProps', - 'render', - 'render', - 'componentDidMount', - ]); - } + expect(log).toEqual([ + 'constructor', + 'constructor', + 'getDerivedStateFromProps', + 'getDerivedStateFromProps', + 'render', + 'render', + 'componentDidMount', + ]); log = []; shouldComponentUpdate = true;