Skip to content

Commit d79faf2

Browse files
author
Brian Vaughn
committed
Split strict effects mode into two flags
One flag ('enableStrictEffects') enables strict mode level 2. It is similar to 'debugRenderPhaseSideEffectsForStrictMode' which enables srtict mode level 1. The second flag ('createRootStrictEffectsByDefault') controls the default strict mode level for 'createRoot' trees. For now, all 'createRoot' trees remain level 1 by default. We will experiment with level 2 within Facebook. This is a prerequisite for adding a configurable option to 'createRoot' that enables choosing a different StrictMode level than the default.
1 parent dd40e13 commit d79faf2

24 files changed

+713
-808
lines changed

packages/react-reconciler/src/ReactFiber.new.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ import type {OffscreenProps} from './ReactFiberOffscreenComponent';
1919

2020
import invariant from 'shared/invariant';
2121
import {
22+
createRootStrictEffectsByDefault,
2223
enableCache,
23-
enableDoubleInvokingEffects,
24+
enableStrictEffects,
2425
enableProfilerTimer,
2526
enableScopeAPI,
2627
} from 'shared/ReactFeatureFlags';
@@ -423,14 +424,14 @@ export function resetWorkInProgress(workInProgress: Fiber, renderLanes: Lanes) {
423424
export function createHostRootFiber(tag: RootTag): Fiber {
424425
let mode;
425426
if (tag === ConcurrentRoot) {
426-
if (enableDoubleInvokingEffects) {
427+
if (enableStrictEffects && createRootStrictEffectsByDefault) {
427428
mode =
428429
ConcurrentMode | BlockingMode | StrictLegacyMode | StrictEffectsMode;
429430
} else {
430431
mode = ConcurrentMode | BlockingMode | StrictLegacyMode;
431432
}
432433
} else if (tag === BlockingRoot) {
433-
if (enableDoubleInvokingEffects) {
434+
if (enableStrictEffects && createRootStrictEffectsByDefault) {
434435
mode = BlockingMode | StrictLegacyMode | StrictEffectsMode;
435436
} else {
436437
mode = BlockingMode | StrictLegacyMode;

packages/react-reconciler/src/ReactFiber.old.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ import type {OffscreenProps} from './ReactFiberOffscreenComponent';
1919

2020
import invariant from 'shared/invariant';
2121
import {
22+
createRootStrictEffectsByDefault,
2223
enableCache,
23-
enableDoubleInvokingEffects,
24+
enableStrictEffects,
2425
enableProfilerTimer,
2526
enableScopeAPI,
2627
} from 'shared/ReactFeatureFlags';
@@ -423,14 +424,14 @@ export function resetWorkInProgress(workInProgress: Fiber, renderLanes: Lanes) {
423424
export function createHostRootFiber(tag: RootTag): Fiber {
424425
let mode;
425426
if (tag === ConcurrentRoot) {
426-
if (enableDoubleInvokingEffects) {
427+
if (enableStrictEffects && createRootStrictEffectsByDefault) {
427428
mode =
428429
ConcurrentMode | BlockingMode | StrictLegacyMode | StrictEffectsMode;
429430
} else {
430431
mode = ConcurrentMode | BlockingMode | StrictLegacyMode;
431432
}
432433
} else if (tag === BlockingRoot) {
433-
if (enableDoubleInvokingEffects) {
434+
if (enableStrictEffects && createRootStrictEffectsByDefault) {
434435
mode = BlockingMode | StrictLegacyMode | StrictEffectsMode;
435436
} else {
436437
mode = BlockingMode | StrictLegacyMode;

packages/react-reconciler/src/ReactFiberClassComponent.new.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
enableDebugTracing,
2020
enableSchedulingProfiler,
2121
warnAboutDeprecatedLifecycles,
22-
enableDoubleInvokingEffects,
22+
enableStrictEffects,
2323
} from 'shared/ReactFeatureFlags';
2424
import ReactStrictModeWarnings from './ReactStrictModeWarnings.new';
2525
import {isMounted} from './ReactFiberTreeReflection';
@@ -908,7 +908,7 @@ function mountClassInstance(
908908
if (typeof instance.componentDidMount === 'function') {
909909
if (
910910
__DEV__ &&
911-
enableDoubleInvokingEffects &&
911+
enableStrictEffects &&
912912
(workInProgress.mode & StrictEffectsMode) !== NoMode
913913
) {
914914
// Never double-invoke effects for legacy roots.
@@ -987,7 +987,7 @@ function resumeMountClassInstance(
987987
if (typeof instance.componentDidMount === 'function') {
988988
if (
989989
__DEV__ &&
990-
enableDoubleInvokingEffects &&
990+
enableStrictEffects &&
991991
(workInProgress.mode & StrictEffectsMode) !== NoMode
992992
) {
993993
// Never double-invoke effects for legacy roots.
@@ -1039,7 +1039,7 @@ function resumeMountClassInstance(
10391039
if (typeof instance.componentDidMount === 'function') {
10401040
if (
10411041
__DEV__ &&
1042-
enableDoubleInvokingEffects &&
1042+
enableStrictEffects &&
10431043
(workInProgress.mode & StrictEffectsMode) !== NoMode
10441044
) {
10451045
// Never double-invoke effects for legacy roots.
@@ -1054,7 +1054,7 @@ function resumeMountClassInstance(
10541054
if (typeof instance.componentDidMount === 'function') {
10551055
if (
10561056
__DEV__ &&
1057-
enableDoubleInvokingEffects &&
1057+
enableStrictEffects &&
10581058
(workInProgress.mode & StrictEffectsMode) !== NoMode
10591059
) {
10601060
// Never double-invoke effects for legacy roots.

packages/react-reconciler/src/ReactFiberClassComponent.old.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
enableDebugTracing,
2020
enableSchedulingProfiler,
2121
warnAboutDeprecatedLifecycles,
22-
enableDoubleInvokingEffects,
22+
enableStrictEffects,
2323
} from 'shared/ReactFeatureFlags';
2424
import ReactStrictModeWarnings from './ReactStrictModeWarnings.old';
2525
import {isMounted} from './ReactFiberTreeReflection';
@@ -908,7 +908,7 @@ function mountClassInstance(
908908
if (typeof instance.componentDidMount === 'function') {
909909
if (
910910
__DEV__ &&
911-
enableDoubleInvokingEffects &&
911+
enableStrictEffects &&
912912
(workInProgress.mode & StrictEffectsMode) !== NoMode
913913
) {
914914
// Never double-invoke effects for legacy roots.
@@ -987,7 +987,7 @@ function resumeMountClassInstance(
987987
if (typeof instance.componentDidMount === 'function') {
988988
if (
989989
__DEV__ &&
990-
enableDoubleInvokingEffects &&
990+
enableStrictEffects &&
991991
(workInProgress.mode & StrictEffectsMode) !== NoMode
992992
) {
993993
// Never double-invoke effects for legacy roots.
@@ -1039,7 +1039,7 @@ function resumeMountClassInstance(
10391039
if (typeof instance.componentDidMount === 'function') {
10401040
if (
10411041
__DEV__ &&
1042-
enableDoubleInvokingEffects &&
1042+
enableStrictEffects &&
10431043
(workInProgress.mode & StrictEffectsMode) !== NoMode
10441044
) {
10451045
// Never double-invoke effects for legacy roots.
@@ -1054,7 +1054,7 @@ function resumeMountClassInstance(
10541054
if (typeof instance.componentDidMount === 'function') {
10551055
if (
10561056
__DEV__ &&
1057-
enableDoubleInvokingEffects &&
1057+
enableStrictEffects &&
10581058
(workInProgress.mode & StrictEffectsMode) !== NoMode
10591059
) {
10601060
// Never double-invoke effects for legacy roots.

packages/react-reconciler/src/ReactFiberCommitWork.new.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {
3535
enableSuspenseServerRenderer,
3636
enableSuspenseCallback,
3737
enableScopeAPI,
38-
enableDoubleInvokingEffects,
38+
enableStrictEffects,
3939
} from 'shared/ReactFeatureFlags';
4040
import {
4141
FunctionComponent,
@@ -2475,7 +2475,7 @@ function ensureCorrectReturnPointer(fiber, expectedReturnFiber) {
24752475
}
24762476

24772477
function invokeLayoutEffectMountInDEV(fiber: Fiber): void {
2478-
if (__DEV__ && enableDoubleInvokingEffects) {
2478+
if (__DEV__ && enableStrictEffects) {
24792479
// We don't need to re-check StrictEffectsMode here.
24802480
// This function is only called if that check has already passed.
24812481
switch (fiber.tag) {
@@ -2509,7 +2509,7 @@ function invokeLayoutEffectMountInDEV(fiber: Fiber): void {
25092509
}
25102510

25112511
function invokePassiveEffectMountInDEV(fiber: Fiber): void {
2512-
if (__DEV__ && enableDoubleInvokingEffects) {
2512+
if (__DEV__ && enableStrictEffects) {
25132513
// We don't need to re-check StrictEffectsMode here.
25142514
// This function is only called if that check has already passed.
25152515
switch (fiber.tag) {
@@ -2534,7 +2534,7 @@ function invokePassiveEffectMountInDEV(fiber: Fiber): void {
25342534
}
25352535

25362536
function invokeLayoutEffectUnmountInDEV(fiber: Fiber): void {
2537-
if (__DEV__ && enableDoubleInvokingEffects) {
2537+
if (__DEV__ && enableStrictEffects) {
25382538
// We don't need to re-check StrictEffectsMode here.
25392539
// This function is only called if that check has already passed.
25402540
switch (fiber.tag) {
@@ -2578,7 +2578,7 @@ function invokeLayoutEffectUnmountInDEV(fiber: Fiber): void {
25782578
}
25792579

25802580
function invokePassiveEffectUnmountInDEV(fiber: Fiber): void {
2581-
if (__DEV__ && enableDoubleInvokingEffects) {
2581+
if (__DEV__ && enableStrictEffects) {
25822582
// We don't need to re-check StrictEffectsMode here.
25832583
// This function is only called if that check has already passed.
25842584
switch (fiber.tag) {

packages/react-reconciler/src/ReactFiberCommitWork.old.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {
3535
enableSuspenseServerRenderer,
3636
enableSuspenseCallback,
3737
enableScopeAPI,
38-
enableDoubleInvokingEffects,
38+
enableStrictEffects,
3939
} from 'shared/ReactFeatureFlags';
4040
import {
4141
FunctionComponent,
@@ -2475,7 +2475,7 @@ function ensureCorrectReturnPointer(fiber, expectedReturnFiber) {
24752475
}
24762476

24772477
function invokeLayoutEffectMountInDEV(fiber: Fiber): void {
2478-
if (__DEV__ && enableDoubleInvokingEffects) {
2478+
if (__DEV__ && enableStrictEffects) {
24792479
// We don't need to re-check StrictEffectsMode here.
24802480
// This function is only called if that check has already passed.
24812481
switch (fiber.tag) {
@@ -2509,7 +2509,7 @@ function invokeLayoutEffectMountInDEV(fiber: Fiber): void {
25092509
}
25102510

25112511
function invokePassiveEffectMountInDEV(fiber: Fiber): void {
2512-
if (__DEV__ && enableDoubleInvokingEffects) {
2512+
if (__DEV__ && enableStrictEffects) {
25132513
// We don't need to re-check StrictEffectsMode here.
25142514
// This function is only called if that check has already passed.
25152515
switch (fiber.tag) {
@@ -2534,7 +2534,7 @@ function invokePassiveEffectMountInDEV(fiber: Fiber): void {
25342534
}
25352535

25362536
function invokeLayoutEffectUnmountInDEV(fiber: Fiber): void {
2537-
if (__DEV__ && enableDoubleInvokingEffects) {
2537+
if (__DEV__ && enableStrictEffects) {
25382538
// We don't need to re-check StrictEffectsMode here.
25392539
// This function is only called if that check has already passed.
25402540
switch (fiber.tag) {
@@ -2578,7 +2578,7 @@ function invokeLayoutEffectUnmountInDEV(fiber: Fiber): void {
25782578
}
25792579

25802580
function invokePassiveEffectUnmountInDEV(fiber: Fiber): void {
2581-
if (__DEV__ && enableDoubleInvokingEffects) {
2581+
if (__DEV__ && enableStrictEffects) {
25822582
// We don't need to re-check StrictEffectsMode here.
25832583
// This function is only called if that check has already passed.
25842584
switch (fiber.tag) {

packages/react-reconciler/src/ReactFiberHooks.new.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
enableCache,
3030
decoupleUpdatePriorityFromScheduler,
3131
enableUseRefAccessWarning,
32-
enableDoubleInvokingEffects,
32+
enableStrictEffects,
3333
} from 'shared/ReactFeatureFlags';
3434

3535
import {
@@ -509,7 +509,7 @@ export function bailoutHooks(
509509
// complete phase (bubbleProperties).
510510
if (
511511
__DEV__ &&
512-
enableDoubleInvokingEffects &&
512+
enableStrictEffects &&
513513
(workInProgress.mode & StrictEffectsMode) !== NoMode
514514
) {
515515
workInProgress.flags &= ~(
@@ -1423,7 +1423,7 @@ function mountEffect(
14231423
}
14241424
if (
14251425
__DEV__ &&
1426-
enableDoubleInvokingEffects &&
1426+
enableStrictEffects &&
14271427
(currentlyRenderingFiber.mode & StrictEffectsMode) !== NoMode
14281428
) {
14291429
return mountEffectImpl(
@@ -1461,7 +1461,7 @@ function mountLayoutEffect(
14611461
): void {
14621462
if (
14631463
__DEV__ &&
1464-
enableDoubleInvokingEffects &&
1464+
enableStrictEffects &&
14651465
(currentlyRenderingFiber.mode & StrictEffectsMode) !== NoMode
14661466
) {
14671467
return mountEffectImpl(
@@ -1533,7 +1533,7 @@ function mountImperativeHandle<T>(
15331533

15341534
if (
15351535
__DEV__ &&
1536-
enableDoubleInvokingEffects &&
1536+
enableStrictEffects &&
15371537
(currentlyRenderingFiber.mode & StrictEffectsMode) !== NoMode
15381538
) {
15391539
return mountEffectImpl(
@@ -1832,7 +1832,7 @@ function mountOpaqueIdentifier(): OpaqueIDType | void {
18321832
if ((currentlyRenderingFiber.mode & BlockingMode) === NoMode) {
18331833
if (
18341834
__DEV__ &&
1835-
enableDoubleInvokingEffects &&
1835+
enableStrictEffects &&
18361836
(currentlyRenderingFiber.mode & StrictEffectsMode) === NoMode
18371837
) {
18381838
currentlyRenderingFiber.flags |= MountPassiveDevEffect | PassiveEffect;

packages/react-reconciler/src/ReactFiberHooks.old.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
enableCache,
3030
decoupleUpdatePriorityFromScheduler,
3131
enableUseRefAccessWarning,
32-
enableDoubleInvokingEffects,
32+
enableStrictEffects,
3333
} from 'shared/ReactFeatureFlags';
3434

3535
import {
@@ -509,7 +509,7 @@ export function bailoutHooks(
509509
// complete phase (bubbleProperties).
510510
if (
511511
__DEV__ &&
512-
enableDoubleInvokingEffects &&
512+
enableStrictEffects &&
513513
(workInProgress.mode & StrictEffectsMode) !== NoMode
514514
) {
515515
workInProgress.flags &= ~(
@@ -1423,7 +1423,7 @@ function mountEffect(
14231423
}
14241424
if (
14251425
__DEV__ &&
1426-
enableDoubleInvokingEffects &&
1426+
enableStrictEffects &&
14271427
(currentlyRenderingFiber.mode & StrictEffectsMode) !== NoMode
14281428
) {
14291429
return mountEffectImpl(
@@ -1461,7 +1461,7 @@ function mountLayoutEffect(
14611461
): void {
14621462
if (
14631463
__DEV__ &&
1464-
enableDoubleInvokingEffects &&
1464+
enableStrictEffects &&
14651465
(currentlyRenderingFiber.mode & StrictEffectsMode) !== NoMode
14661466
) {
14671467
return mountEffectImpl(
@@ -1533,7 +1533,7 @@ function mountImperativeHandle<T>(
15331533

15341534
if (
15351535
__DEV__ &&
1536-
enableDoubleInvokingEffects &&
1536+
enableStrictEffects &&
15371537
(currentlyRenderingFiber.mode & StrictEffectsMode) !== NoMode
15381538
) {
15391539
return mountEffectImpl(
@@ -1832,7 +1832,7 @@ function mountOpaqueIdentifier(): OpaqueIDType | void {
18321832
if ((currentlyRenderingFiber.mode & BlockingMode) === NoMode) {
18331833
if (
18341834
__DEV__ &&
1835-
enableDoubleInvokingEffects &&
1835+
enableStrictEffects &&
18361836
(currentlyRenderingFiber.mode & StrictEffectsMode) === NoMode
18371837
) {
18381838
currentlyRenderingFiber.flags |= MountPassiveDevEffect | PassiveEffect;

packages/react-reconciler/src/ReactFiberWorkLoop.new.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
enableDebugTracing,
3333
enableSchedulingProfiler,
3434
disableSchedulerTimeoutInWorkLoop,
35-
enableDoubleInvokingEffects,
35+
enableStrictEffects,
3636
skipUnmountedBoundaries,
3737
enableNativeEventPriorityInference,
3838
} from 'shared/ReactFeatureFlags';
@@ -2071,7 +2071,7 @@ function commitRootImpl(root, renderPriorityLevel) {
20712071
legacyErrorBoundariesThatAlreadyFailed = null;
20722072
}
20732073

2074-
if (__DEV__ && enableDoubleInvokingEffects) {
2074+
if (__DEV__ && enableStrictEffects) {
20752075
if (!rootDidHavePassiveEffects) {
20762076
commitDoubleInvokeEffectsInDEV(root.current, false);
20772077
}
@@ -2258,7 +2258,7 @@ function flushPassiveEffectsImpl() {
22582258
markPassiveEffectsStopped();
22592259
}
22602260

2261-
if (__DEV__ && enableDoubleInvokingEffects) {
2261+
if (__DEV__ && enableStrictEffects) {
22622262
commitDoubleInvokeEffectsInDEV(root.current, true);
22632263
}
22642264

@@ -2561,7 +2561,7 @@ function commitDoubleInvokeEffectsInDEV(
25612561
fiber: Fiber,
25622562
hasPassiveEffects: boolean,
25632563
) {
2564-
if (__DEV__ && enableDoubleInvokingEffects) {
2564+
if (__DEV__ && enableStrictEffects) {
25652565
// Never double-invoke effects outside of StrictEffectsMode.
25662566
if ((fiber.mode & StrictEffectsMode) === NoMode) {
25672567
return;
@@ -2590,7 +2590,7 @@ function invokeEffectsInDev(
25902590
fiberFlags: Flags,
25912591
invokeEffectFn: (fiber: Fiber) => void,
25922592
): void {
2593-
if (__DEV__ && enableDoubleInvokingEffects) {
2593+
if (__DEV__ && enableStrictEffects) {
25942594
// We don't need to re-check StrictEffectsMode here.
25952595
// This function is only called if that check has already passed.
25962596

0 commit comments

Comments
 (0)