From faf6c4dfdcd3c9b3862af6a3afcb3d80abd407c0 Mon Sep 17 00:00:00 2001 From: Ricky Date: Wed, 18 Dec 2024 17:51:12 -0500 Subject: [PATCH] [flags] Remove debugRenderPhaseSideEffectsForStrictMode (#31839) This is enabled everywhere, we can just use the inline `__DEV__` checks. --- .../react-reconciler/src/ReactFiberBeginWork.js | 6 +----- .../src/ReactFiberClassComponent.js | 16 +++------------- .../src/ReactFiberClassUpdateQueue.js | 12 ++---------- packages/react-reconciler/src/ReactFiberHooks.js | 5 +---- .../src/__tests__/ReactHooks-test.internal.js | 6 ------ .../src/__tests__/ReactUpdaters-test.internal.js | 1 - .../src/__tests__/useRef-test.internal.js | 3 --- .../react/src/__tests__/ReactStrictMode-test.js | 10 +++++----- packages/shared/ReactFeatureFlags.js | 4 ---- .../shared/forks/ReactFeatureFlags.native-fb.js | 1 - .../shared/forks/ReactFeatureFlags.native-oss.js | 6 +----- .../forks/ReactFeatureFlags.test-renderer.js | 1 - .../ReactFeatureFlags.test-renderer.native-fb.js | 1 - .../forks/ReactFeatureFlags.test-renderer.www.js | 1 - packages/shared/forks/ReactFeatureFlags.www.js | 1 - 15 files changed, 13 insertions(+), 61 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberBeginWork.js b/packages/react-reconciler/src/ReactFiberBeginWork.js index 632b2df70c097..71affb7ca7a44 100644 --- a/packages/react-reconciler/src/ReactFiberBeginWork.js +++ b/packages/react-reconciler/src/ReactFiberBeginWork.js @@ -92,7 +92,6 @@ import { DidDefer, } from './ReactFiberFlags'; import { - debugRenderPhaseSideEffectsForStrictMode, disableLegacyContext, disableLegacyContextForFunctionComponents, enableProfilerCommitHooks, @@ -1375,10 +1374,7 @@ function finishClassComponent( } if (__DEV__) { nextChildren = callRenderInDEV(instance); - if ( - debugRenderPhaseSideEffectsForStrictMode && - workInProgress.mode & StrictLegacyMode - ) { + if (workInProgress.mode & StrictLegacyMode) { setIsStrictModeForDevtools(true); try { callRenderInDEV(instance); diff --git a/packages/react-reconciler/src/ReactFiberClassComponent.js b/packages/react-reconciler/src/ReactFiberClassComponent.js index 7ebf0fb9f4b92..d0490b7e02d4e 100644 --- a/packages/react-reconciler/src/ReactFiberClassComponent.js +++ b/packages/react-reconciler/src/ReactFiberClassComponent.js @@ -18,7 +18,6 @@ import { MountLayoutDev, } from './ReactFiberFlags'; import { - debugRenderPhaseSideEffectsForStrictMode, disableLegacyContext, enableSchedulingProfiler, disableDefaultPropsExceptForClasses, @@ -138,10 +137,7 @@ function applyDerivedStateFromProps( const prevState = workInProgress.memoizedState; let partialState = getDerivedStateFromProps(nextProps, prevState); if (__DEV__) { - if ( - debugRenderPhaseSideEffectsForStrictMode && - workInProgress.mode & StrictLegacyMode - ) { + if (workInProgress.mode & StrictLegacyMode) { setIsStrictModeForDevtools(true); try { // Invoke the function an extra time to help detect side-effects. @@ -266,10 +262,7 @@ function checkShouldComponentUpdate( nextContext, ); if (__DEV__) { - if ( - debugRenderPhaseSideEffectsForStrictMode && - workInProgress.mode & StrictLegacyMode - ) { + if (workInProgress.mode & StrictLegacyMode) { setIsStrictModeForDevtools(true); try { // Invoke the function an extra time to help detect side-effects. @@ -598,10 +591,7 @@ function constructClassInstance( let instance = new ctor(props, context); // Instantiate twice to help detect side-effects. if (__DEV__) { - if ( - debugRenderPhaseSideEffectsForStrictMode && - workInProgress.mode & StrictLegacyMode - ) { + if (workInProgress.mode & StrictLegacyMode) { setIsStrictModeForDevtools(true); try { instance = new ctor(props, context); diff --git a/packages/react-reconciler/src/ReactFiberClassUpdateQueue.js b/packages/react-reconciler/src/ReactFiberClassUpdateQueue.js index 7945e4fb1c915..23bef1e6b0983 100644 --- a/packages/react-reconciler/src/ReactFiberClassUpdateQueue.js +++ b/packages/react-reconciler/src/ReactFiberClassUpdateQueue.js @@ -110,8 +110,6 @@ import { } from './ReactFiberFlags'; import getComponentNameFromFiber from './getComponentNameFromFiber'; -import {debugRenderPhaseSideEffectsForStrictMode} from 'shared/ReactFeatureFlags'; - import {StrictLegacyMode} from './ReactTypeOfMode'; import { markSkippedUpdateLanes, @@ -402,10 +400,7 @@ function getStateFromUpdate( } const nextState = payload.call(instance, prevState, nextProps); if (__DEV__) { - if ( - debugRenderPhaseSideEffectsForStrictMode && - workInProgress.mode & StrictLegacyMode - ) { + if (workInProgress.mode & StrictLegacyMode) { setIsStrictModeForDevtools(true); try { payload.call(instance, prevState, nextProps); @@ -435,10 +430,7 @@ function getStateFromUpdate( } partialState = payload.call(instance, prevState, nextProps); if (__DEV__) { - if ( - debugRenderPhaseSideEffectsForStrictMode && - workInProgress.mode & StrictLegacyMode - ) { + if (workInProgress.mode & StrictLegacyMode) { setIsStrictModeForDevtools(true); try { payload.call(instance, prevState, nextProps); diff --git a/packages/react-reconciler/src/ReactFiberHooks.js b/packages/react-reconciler/src/ReactFiberHooks.js index 99dbea044690f..e76b78b2ce2a8 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.js +++ b/packages/react-reconciler/src/ReactFiberHooks.js @@ -40,7 +40,6 @@ import { enableUseEffectEventHook, enableUseResourceEffectHook, enableLegacyCache, - debugRenderPhaseSideEffectsForStrictMode, disableLegacyMode, enableNoCloningMemoCache, } from 'shared/ReactFeatureFlags'; @@ -623,9 +622,7 @@ export function renderWithHooks( // // There are plenty of tests to ensure this behavior is correct. const shouldDoubleRenderDEV = - __DEV__ && - debugRenderPhaseSideEffectsForStrictMode && - (workInProgress.mode & StrictLegacyMode) !== NoMode; + __DEV__ && (workInProgress.mode & StrictLegacyMode) !== NoMode; shouldDoubleInvokeUserFnsInHooksDEV = shouldDoubleRenderDEV; let children = __DEV__ diff --git a/packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js b/packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js index 556e0559728e7..8b0e903a839e9 100644 --- a/packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js @@ -13,7 +13,6 @@ 'use strict'; let React; -let ReactFeatureFlags; let ReactTestRenderer; let Scheduler; let ReactDOMServer; @@ -26,8 +25,6 @@ let waitForThrow; describe('ReactHooks', () => { beforeEach(() => { jest.resetModules(); - ReactFeatureFlags = require('shared/ReactFeatureFlags'); - React = require('react'); ReactTestRenderer = require('react-test-renderer'); Scheduler = require('scheduler'); @@ -1240,8 +1237,6 @@ describe('ReactHooks', () => { }); it('double-invokes components with Hooks in Strict Mode', async () => { - ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = true; - const {useState, StrictMode} = React; let renderCount = 0; @@ -1459,7 +1454,6 @@ describe('ReactHooks', () => { }); it('double-invokes useMemo in DEV StrictMode despite []', async () => { - ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = true; const {useMemo, StrictMode} = React; let useMemoCount = 0; diff --git a/packages/react-reconciler/src/__tests__/ReactUpdaters-test.internal.js b/packages/react-reconciler/src/__tests__/ReactUpdaters-test.internal.js index 3f7fcd28aec3d..3aa76b0c2ddfa 100644 --- a/packages/react-reconciler/src/__tests__/ReactUpdaters-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactUpdaters-test.internal.js @@ -34,7 +34,6 @@ describe('updaters', () => { ReactFeatureFlags = require('shared/ReactFeatureFlags'); ReactFeatureFlags.enableUpdaterTracking = true; - ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false; mockDevToolsHook = { injectInternals: jest.fn(() => {}), diff --git a/packages/react-reconciler/src/__tests__/useRef-test.internal.js b/packages/react-reconciler/src/__tests__/useRef-test.internal.js index 19a8d29211df0..2a6ab6ab58cca 100644 --- a/packages/react-reconciler/src/__tests__/useRef-test.internal.js +++ b/packages/react-reconciler/src/__tests__/useRef-test.internal.js @@ -28,9 +28,6 @@ describe('useRef', () => { ReactNoop = require('react-noop-renderer'); Scheduler = require('scheduler'); - const ReactFeatureFlags = require('shared/ReactFeatureFlags'); - ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false; - act = require('internal-test-utils').act; useCallback = React.useCallback; useEffect = React.useEffect; diff --git a/packages/react/src/__tests__/ReactStrictMode-test.js b/packages/react/src/__tests__/ReactStrictMode-test.js index 863f84ebdb291..f28c70a871665 100644 --- a/packages/react/src/__tests__/ReactStrictMode-test.js +++ b/packages/react/src/__tests__/ReactStrictMode-test.js @@ -202,7 +202,7 @@ describe('ReactStrictMode', () => { expect(instance.state.count).toBe(2); }); - // @gate debugRenderPhaseSideEffectsForStrictMode + // @gate __DEV__ it('double invokes useState and useReducer initializers functions', async () => { const log = []; @@ -390,7 +390,7 @@ describe('ReactStrictMode', () => { expect(instance.state.count).toBe(2); }); - // @gate debugRenderPhaseSideEffectsForStrictMode + // @gate __DEV__ it('double invokes useMemo functions', async () => { let log = []; @@ -436,7 +436,7 @@ describe('ReactStrictMode', () => { ]); }); - // @gate debugRenderPhaseSideEffectsForStrictMode + // @gate __DEV__ it('double invokes useMemo functions with first result', async () => { let log = []; function Uppercased({text}) { @@ -499,7 +499,7 @@ describe('ReactStrictMode', () => { expect(log[2]).toBe(log[3]); }); - // @gate debugRenderPhaseSideEffectsForStrictMode + // @gate __DEV__ it('double invokes setState updater functions', async () => { const log = []; @@ -532,7 +532,7 @@ describe('ReactStrictMode', () => { expect(log).toEqual(['Compute count: 1', 'Compute count: 1']); }); - // @gate debugRenderPhaseSideEffectsForStrictMode + // @gate __DEV__ it('double invokes reducer functions', async () => { const log = []; diff --git a/packages/shared/ReactFeatureFlags.js b/packages/shared/ReactFeatureFlags.js index 7d45abe69f5a9..3046f8f4cb45e 100644 --- a/packages/shared/ReactFeatureFlags.js +++ b/packages/shared/ReactFeatureFlags.js @@ -234,10 +234,6 @@ export const disableTextareaChildren = false; // Debugging and DevTools // ----------------------------------------------------------------------------- -// Helps identify side effects in render-phase lifecycle hooks and setState -// reducers by double invoking them in StrictLegacyMode. -export const debugRenderPhaseSideEffectsForStrictMode = __DEV__; - // Gather advanced timing metrics for Profiler subtrees. export const enableProfilerTimer = __PROFILE__; diff --git a/packages/shared/forks/ReactFeatureFlags.native-fb.js b/packages/shared/forks/ReactFeatureFlags.native-fb.js index 73ccd5fb8eda9..4ea9499e6ca80 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-fb.js +++ b/packages/shared/forks/ReactFeatureFlags.native-fb.js @@ -32,7 +32,6 @@ export const { } = dynamicFlags; // The rest of the flags are static for better dead code elimination. -export const debugRenderPhaseSideEffectsForStrictMode = __DEV__; export const disableClientCache = true; export const disableCommentsAsDOMContainers = true; export const disableDefaultPropsExceptForClasses = true; diff --git a/packages/shared/forks/ReactFeatureFlags.native-oss.js b/packages/shared/forks/ReactFeatureFlags.native-oss.js index 7699aa73f7fa7..dddd80aeea82a 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-oss.js +++ b/packages/shared/forks/ReactFeatureFlags.native-oss.js @@ -12,12 +12,8 @@ import typeof * as ExportsType from './ReactFeatureFlags.native-oss'; // TODO: Align these flags with canary and delete this file once RN ships from Canary. -// DEV-only but enabled in the next RN Major. -// Not supported by flag script to avoid the special case. -export const debugRenderPhaseSideEffectsForStrictMode = __DEV__; - // ----------------------------------------------------------------------------- -// All other flags +// All flags // ----------------------------------------------------------------------------- export const alwaysThrottleRetries = false; export const disableClientCache = true; diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.js index c23c4ba131a72..95826007dc9cd 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.js @@ -10,7 +10,6 @@ import typeof * as FeatureFlagsType from 'shared/ReactFeatureFlags'; import typeof * as ExportsType from './ReactFeatureFlags.test-renderer'; -export const debugRenderPhaseSideEffectsForStrictMode = __DEV__; export const enableAsyncDebugInfo = false; export const enableSchedulingProfiler = false; export const enableProfilerTimer = __PROFILE__; diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js index 8574f34c4e952..8d38112b16879 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js @@ -11,7 +11,6 @@ import typeof * as FeatureFlagsType from 'shared/ReactFeatureFlags'; import typeof * as ExportsType from './ReactFeatureFlags.test-renderer'; export const alwaysThrottleRetries = false; -export const debugRenderPhaseSideEffectsForStrictMode = __DEV__; export const disableClientCache = true; export const disableCommentsAsDOMContainers = true; export const disableDefaultPropsExceptForClasses = true; diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js index 97743f0d46ae9..28a303a034cac 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js @@ -10,7 +10,6 @@ import typeof * as FeatureFlagsType from 'shared/ReactFeatureFlags'; import typeof * as ExportsType from './ReactFeatureFlags.test-renderer.www'; -export const debugRenderPhaseSideEffectsForStrictMode = __DEV__; export const enableAsyncDebugInfo = false; export const enableSchedulingProfiler = false; export const enableProfilerTimer = __PROFILE__; diff --git a/packages/shared/forks/ReactFeatureFlags.www.js b/packages/shared/forks/ReactFeatureFlags.www.js index c027e2bdc121c..cf514f93d43ac 100644 --- a/packages/shared/forks/ReactFeatureFlags.www.js +++ b/packages/shared/forks/ReactFeatureFlags.www.js @@ -42,7 +42,6 @@ export const { // On WWW, __EXPERIMENTAL__ is used for a new modern build. // It's not used anywhere in production yet. -export const debugRenderPhaseSideEffectsForStrictMode = __DEV__; export const enableProfilerTimer = __PROFILE__; export const enableProfilerCommitHooks = __PROFILE__; export const enableProfilerNestedUpdatePhase = __PROFILE__;