@samitouri / QOS-React-2 / commits / faf6c4dfdc

[flags] Remove debugRenderPhaseSideEffectsForStrictMode (#31839)

This is enabled everywhere, we can just use the inline `__DEV__` checks.

Ricky committed Dec 18, 2024 at 17:51 UTC faf6c4dfdcd3c9b3862af6a3afcb3d80abd407c0
15 files changed +13 -61
packages/react-reconciler/src/ReactFiberBeginWork.js
+1 -5
@@ -92,7 +92,6 @@ import {
92 DidDefer,
93 } from './ReactFiberFlags';
94 import {
95 - debugRenderPhaseSideEffectsForStrictMode,
95 disableLegacyContext,
96 disableLegacyContextForFunctionComponents,
97 enableProfilerCommitHooks,
@@ -1375,10 +1374,7 @@ function finishClassComponent(
1374 }
1375 if (__DEV__) {
1376 nextChildren = callRenderInDEV(instance);
1378 - if (
1379 - debugRenderPhaseSideEffectsForStrictMode &&
1380 - workInProgress.mode & StrictLegacyMode
1381 - ) {
1377 + if (workInProgress.mode & StrictLegacyMode) {
1378 setIsStrictModeForDevtools(true);
1379 try {
1380 callRenderInDEV(instance);
packages/react-reconciler/src/ReactFiberClassComponent.js
+3 -13
@@ -18,7 +18,6 @@ import {
18 MountLayoutDev,
19 } from './ReactFiberFlags';
20 import {
21 - debugRenderPhaseSideEffectsForStrictMode,
21 disableLegacyContext,
22 enableSchedulingProfiler,
23 disableDefaultPropsExceptForClasses,
@@ -138,10 +137,7 @@ function applyDerivedStateFromProps(
137 const prevState = workInProgress.memoizedState;
138 let partialState = getDerivedStateFromProps(nextProps, prevState);
139 if (__DEV__) {
141 - if (
142 - debugRenderPhaseSideEffectsForStrictMode &&
143 - workInProgress.mode & StrictLegacyMode
144 - ) {
140 + if (workInProgress.mode & StrictLegacyMode) {
141 setIsStrictModeForDevtools(true);
142 try {
143 // Invoke the function an extra time to help detect side-effects.
@@ -266,10 +262,7 @@ function checkShouldComponentUpdate(
262 nextContext,
263 );
264 if (__DEV__) {
269 - if (
270 - debugRenderPhaseSideEffectsForStrictMode &&
271 - workInProgress.mode & StrictLegacyMode
272 - ) {
265 + if (workInProgress.mode & StrictLegacyMode) {
266 setIsStrictModeForDevtools(true);
267 try {
268 // Invoke the function an extra time to help detect side-effects.
@@ -598,10 +591,7 @@ function constructClassInstance(
591 let instance = new ctor(props, context);
592 // Instantiate twice to help detect side-effects.
593 if (__DEV__) {
601 - if (
602 - debugRenderPhaseSideEffectsForStrictMode &&
603 - workInProgress.mode & StrictLegacyMode
604 - ) {
594 + if (workInProgress.mode & StrictLegacyMode) {
595 setIsStrictModeForDevtools(true);
596 try {
597 instance = new ctor(props, context);
packages/react-reconciler/src/ReactFiberClassUpdateQueue.js
+2 -10
@@ -110,8 +110,6 @@ import {
110 } from './ReactFiberFlags';
111 import getComponentNameFromFiber from './getComponentNameFromFiber';
112
113 -import {debugRenderPhaseSideEffectsForStrictMode} from 'shared/ReactFeatureFlags';
114 -
113 import {StrictLegacyMode} from './ReactTypeOfMode';
114 import {
115 markSkippedUpdateLanes,
@@ -402,10 +400,7 @@ function getStateFromUpdate<State>(
400 }
401 const nextState = payload.call(instance, prevState, nextProps);
402 if (__DEV__) {
405 - if (
406 - debugRenderPhaseSideEffectsForStrictMode &&
407 - workInProgress.mode & StrictLegacyMode
408 - ) {
403 + if (workInProgress.mode & StrictLegacyMode) {
404 setIsStrictModeForDevtools(true);
405 try {
406 payload.call(instance, prevState, nextProps);
@@ -435,10 +430,7 @@ function getStateFromUpdate<State>(
430 }
431 partialState = payload.call(instance, prevState, nextProps);
432 if (__DEV__) {
438 - if (
439 - debugRenderPhaseSideEffectsForStrictMode &&
440 - workInProgress.mode & StrictLegacyMode
441 - ) {
433 + if (workInProgress.mode & StrictLegacyMode) {
434 setIsStrictModeForDevtools(true);
435 try {
436 payload.call(instance, prevState, nextProps);
packages/react-reconciler/src/ReactFiberHooks.js
+1 -4
@@ -40,7 +40,6 @@ import {
40 enableUseEffectEventHook,
41 enableUseResourceEffectHook,
42 enableLegacyCache,
43 - debugRenderPhaseSideEffectsForStrictMode,
43 disableLegacyMode,
44 enableNoCloningMemoCache,
45 } from 'shared/ReactFeatureFlags';
@@ -623,9 +622,7 @@ export function renderWithHooks<Props, SecondArg>(
622 //
623 // There are plenty of tests to ensure this behavior is correct.
624 const shouldDoubleRenderDEV =
626 - __DEV__ &&
627 - debugRenderPhaseSideEffectsForStrictMode &&
628 - (workInProgress.mode & StrictLegacyMode) !== NoMode;
625 + __DEV__ && (workInProgress.mode & StrictLegacyMode) !== NoMode;
626
627 shouldDoubleInvokeUserFnsInHooksDEV = shouldDoubleRenderDEV;
628 let children = __DEV__
packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js
-6
@@ -13,7 +13,6 @@
13 'use strict';
14
15 let React;
16 -let ReactFeatureFlags;
16 let ReactTestRenderer;
17 let Scheduler;
18 let ReactDOMServer;
@@ -26,8 +25,6 @@ let waitForThrow;
25 describe('ReactHooks', () => {
26 beforeEach(() => {
27 jest.resetModules();
29 - ReactFeatureFlags = require('shared/ReactFeatureFlags');
30 -
28 React = require('react');
29 ReactTestRenderer = require('react-test-renderer');
30 Scheduler = require('scheduler');
@@ -1240,8 +1237,6 @@ describe('ReactHooks', () => {
1237 });
1238
1239 it('double-invokes components with Hooks in Strict Mode', async () => {
1243 - ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = true;
1244 -
1240 const {useState, StrictMode} = React;
1241 let renderCount = 0;
1242
@@ -1459,7 +1454,6 @@ describe('ReactHooks', () => {
1454 });
1455
1456 it('double-invokes useMemo in DEV StrictMode despite []', async () => {
1462 - ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = true;
1457 const {useMemo, StrictMode} = React;
1458
1459 let useMemoCount = 0;
packages/react-reconciler/src/__tests__/ReactUpdaters-test.internal.js
-1
@@ -34,7 +34,6 @@ describe('updaters', () => {
34
35 ReactFeatureFlags = require('shared/ReactFeatureFlags');
36 ReactFeatureFlags.enableUpdaterTracking = true;
37 - ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;
37
38 mockDevToolsHook = {
39 injectInternals: jest.fn(() => {}),
packages/react-reconciler/src/__tests__/useRef-test.internal.js
-3
@@ -28,9 +28,6 @@ describe('useRef', () => {
28 ReactNoop = require('react-noop-renderer');
29 Scheduler = require('scheduler');
30
31 - const ReactFeatureFlags = require('shared/ReactFeatureFlags');
32 - ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;
33 -
31 act = require('internal-test-utils').act;
32 useCallback = React.useCallback;
33 useEffect = React.useEffect;
packages/react/src/__tests__/ReactStrictMode-test.js
+5 -5
@@ -202,7 +202,7 @@ describe('ReactStrictMode', () => {
202 expect(instance.state.count).toBe(2);
203 });
204
205 - // @gate debugRenderPhaseSideEffectsForStrictMode
205 + // @gate __DEV__
206 it('double invokes useState and useReducer initializers functions', async () => {
207 const log = [];
208
@@ -390,7 +390,7 @@ describe('ReactStrictMode', () => {
390 expect(instance.state.count).toBe(2);
391 });
392
393 - // @gate debugRenderPhaseSideEffectsForStrictMode
393 + // @gate __DEV__
394 it('double invokes useMemo functions', async () => {
395 let log = [];
396
@@ -436,7 +436,7 @@ describe('ReactStrictMode', () => {
436 ]);
437 });
438
439 - // @gate debugRenderPhaseSideEffectsForStrictMode
439 + // @gate __DEV__
440 it('double invokes useMemo functions with first result', async () => {
441 let log = [];
442 function Uppercased({text}) {
@@ -499,7 +499,7 @@ describe('ReactStrictMode', () => {
499 expect(log[2]).toBe(log[3]);
500 });
501
502 - // @gate debugRenderPhaseSideEffectsForStrictMode
502 + // @gate __DEV__
503 it('double invokes setState updater functions', async () => {
504 const log = [];
505
@@ -532,7 +532,7 @@ describe('ReactStrictMode', () => {
532 expect(log).toEqual(['Compute count: 1', 'Compute count: 1']);
533 });
534
535 - // @gate debugRenderPhaseSideEffectsForStrictMode
535 + // @gate __DEV__
536 it('double invokes reducer functions', async () => {
537 const log = [];
538
packages/shared/ReactFeatureFlags.js
-4
@@ -234,10 +234,6 @@ export const disableTextareaChildren = false;
234 // Debugging and DevTools
235 // -----------------------------------------------------------------------------
236
237 -// Helps identify side effects in render-phase lifecycle hooks and setState
238 -// reducers by double invoking them in StrictLegacyMode.
239 -export const debugRenderPhaseSideEffectsForStrictMode = __DEV__;
240 -
237 // Gather advanced timing metrics for Profiler subtrees.
238 export const enableProfilerTimer = __PROFILE__;
239
packages/shared/forks/ReactFeatureFlags.native-fb.js
-1
@@ -32,7 +32,6 @@ export const {
32 } = dynamicFlags;
33
34 // The rest of the flags are static for better dead code elimination.
35 -export const debugRenderPhaseSideEffectsForStrictMode = __DEV__;
35 export const disableClientCache = true;
36 export const disableCommentsAsDOMContainers = true;
37 export const disableDefaultPropsExceptForClasses = true;
packages/shared/forks/ReactFeatureFlags.native-oss.js
+1 -5
@@ -12,12 +12,8 @@ import typeof * as ExportsType from './ReactFeatureFlags.native-oss';
12
13 // TODO: Align these flags with canary and delete this file once RN ships from Canary.
14
15 -// DEV-only but enabled in the next RN Major.
16 -// Not supported by flag script to avoid the special case.
17 -export const debugRenderPhaseSideEffectsForStrictMode = __DEV__;
18 -
15 // -----------------------------------------------------------------------------
20 -// All other flags
16 +// All flags
17 // -----------------------------------------------------------------------------
18 export const alwaysThrottleRetries = false;
19 export const disableClientCache = true;
packages/shared/forks/ReactFeatureFlags.test-renderer.js
-1
@@ -10,7 +10,6 @@
10 import typeof * as FeatureFlagsType from 'shared/ReactFeatureFlags';
11 import typeof * as ExportsType from './ReactFeatureFlags.test-renderer';
12
13 -export const debugRenderPhaseSideEffectsForStrictMode = __DEV__;
13 export const enableAsyncDebugInfo = false;
14 export const enableSchedulingProfiler = false;
15 export const enableProfilerTimer = __PROFILE__;
packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js
-1
@@ -11,7 +11,6 @@ import typeof * as FeatureFlagsType from 'shared/ReactFeatureFlags';
11 import typeof * as ExportsType from './ReactFeatureFlags.test-renderer';
12
13 export const alwaysThrottleRetries = false;
14 -export const debugRenderPhaseSideEffectsForStrictMode = __DEV__;
14 export const disableClientCache = true;
15 export const disableCommentsAsDOMContainers = true;
16 export const disableDefaultPropsExceptForClasses = true;
packages/shared/forks/ReactFeatureFlags.test-renderer.www.js
-1
@@ -10,7 +10,6 @@
10 import typeof * as FeatureFlagsType from 'shared/ReactFeatureFlags';
11 import typeof * as ExportsType from './ReactFeatureFlags.test-renderer.www';
12
13 -export const debugRenderPhaseSideEffectsForStrictMode = __DEV__;
13 export const enableAsyncDebugInfo = false;
14 export const enableSchedulingProfiler = false;
15 export const enableProfilerTimer = __PROFILE__;
packages/shared/forks/ReactFeatureFlags.www.js
-1
@@ -42,7 +42,6 @@ export const {
42 // On WWW, __EXPERIMENTAL__ is used for a new modern build.
43 // It's not used anywhere in production yet.
44
45 -export const debugRenderPhaseSideEffectsForStrictMode = __DEV__;
45 export const enableProfilerTimer = __PROFILE__;
46 export const enableProfilerCommitHooks = __PROFILE__;
47 export const enableProfilerNestedUpdatePhase = __PROFILE__;