Skip to content

[flags] Remove debugRenderPhaseSideEffectsForStrictMode #31839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ import {
DidDefer,
} from './ReactFiberFlags';
import {
debugRenderPhaseSideEffectsForStrictMode,
disableLegacyContext,
disableLegacyContextForFunctionComponents,
enableProfilerCommitHooks,
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 3 additions & 13 deletions packages/react-reconciler/src/ReactFiberClassComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
MountLayoutDev,
} from './ReactFiberFlags';
import {
debugRenderPhaseSideEffectsForStrictMode,
disableLegacyContext,
enableSchedulingProfiler,
disableDefaultPropsExceptForClasses,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 2 additions & 10 deletions packages/react-reconciler/src/ReactFiberClassUpdateQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ import {
} from './ReactFiberFlags';
import getComponentNameFromFiber from './getComponentNameFromFiber';

import {debugRenderPhaseSideEffectsForStrictMode} from 'shared/ReactFeatureFlags';

import {StrictLegacyMode} from './ReactTypeOfMode';
import {
markSkippedUpdateLanes,
Expand Down Expand Up @@ -402,10 +400,7 @@ function getStateFromUpdate<State>(
}
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);
Expand Down Expand Up @@ -435,10 +430,7 @@ function getStateFromUpdate<State>(
}
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);
Expand Down
5 changes: 1 addition & 4 deletions packages/react-reconciler/src/ReactFiberHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import {
enableUseEffectEventHook,
enableUseResourceEffectHook,
enableLegacyCache,
debugRenderPhaseSideEffectsForStrictMode,
disableLegacyMode,
enableNoCloningMemoCache,
} from 'shared/ReactFeatureFlags';
Expand Down Expand Up @@ -623,9 +622,7 @@ export function renderWithHooks<Props, SecondArg>(
//
// 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__
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
'use strict';

let React;
let ReactFeatureFlags;
let ReactTestRenderer;
let Scheduler;
let ReactDOMServer;
Expand All @@ -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');
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ describe('updaters', () => {

ReactFeatureFlags = require('shared/ReactFeatureFlags');
ReactFeatureFlags.enableUpdaterTracking = true;
ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;

mockDevToolsHook = {
injectInternals: jest.fn(() => {}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions packages/react/src/__tests__/ReactStrictMode-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down Expand Up @@ -390,7 +390,7 @@ describe('ReactStrictMode', () => {
expect(instance.state.count).toBe(2);
});

// @gate debugRenderPhaseSideEffectsForStrictMode
// @gate __DEV__
it('double invokes useMemo functions', async () => {
let log = [];

Expand Down Expand Up @@ -436,7 +436,7 @@ describe('ReactStrictMode', () => {
]);
});

// @gate debugRenderPhaseSideEffectsForStrictMode
// @gate __DEV__
it('double invokes useMemo functions with first result', async () => {
let log = [];
function Uppercased({text}) {
Expand Down Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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 = [];

Expand Down
4 changes: 0 additions & 4 deletions packages/shared/ReactFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,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__;

Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.native-fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 1 addition & 5 deletions packages/shared/forks/ReactFeatureFlags.native-oss.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.test-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__;
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -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__;
Expand Down
Loading