Skip to content
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

Remove feature flag enableStrictEffects #25387

Merged
merged 2 commits into from
Oct 19, 2022
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
11 changes: 2 additions & 9 deletions packages/react-reconciler/src/ReactFiber.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {supportsResources, isHostResourceType} from './ReactFiberHostConfig';
import {
createRootStrictEffectsByDefault,
enableCache,
enableStrictEffects,
enableProfilerTimer,
enableScopeAPI,
enableLegacyHidden,
Expand Down Expand Up @@ -442,13 +441,7 @@ export function createHostRootFiber(
let mode;
if (tag === ConcurrentRoot) {
mode = ConcurrentMode;
if (isStrictMode === true) {
mode |= StrictLegacyMode;

if (enableStrictEffects) {
mode |= StrictEffectsMode;
}
} else if (enableStrictEffects && createRootStrictEffectsByDefault) {
if (isStrictMode === true || createRootStrictEffectsByDefault) {
mode |= StrictLegacyMode | StrictEffectsMode;
}
if (
Expand Down Expand Up @@ -511,7 +504,7 @@ export function createFiberFromTypeAndProps(
case REACT_STRICT_MODE_TYPE:
fiberTag = Mode;
mode |= StrictLegacyMode;
if (enableStrictEffects && (mode & ConcurrentMode) !== NoMode) {
if ((mode & ConcurrentMode) !== NoMode) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since enableStrictEffects used to be set to __DEV__, does this mean we flip this flag in prod more often (here and in other places where there's no __DEV__ check). Does this matter? It seems good for consistency to always set StrictLegacyMode together with StrictEffectsMode but I want to make sure there's no accidental assumptions about which flags are DEV-only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it matters. StrictMode itself has a check to see if __DEV__ is true or not. So even if this flag gets flipped more often than before, it will not cause StrictMode to be triggered in prod.
I'm trying to reduce complexity around StrictMode, it seems unnecessary to have several flags controlling it, we want to behaviour to be consistent.

// Strict effects should never run on legacy roots
mode |= StrictEffectsMode;
}
Expand Down
11 changes: 2 additions & 9 deletions packages/react-reconciler/src/ReactFiber.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {supportsResources, isHostResourceType} from './ReactFiberHostConfig';
import {
createRootStrictEffectsByDefault,
enableCache,
enableStrictEffects,
enableProfilerTimer,
enableScopeAPI,
enableLegacyHidden,
Expand Down Expand Up @@ -442,13 +441,7 @@ export function createHostRootFiber(
let mode;
if (tag === ConcurrentRoot) {
mode = ConcurrentMode;
if (isStrictMode === true) {
mode |= StrictLegacyMode;

if (enableStrictEffects) {
mode |= StrictEffectsMode;
}
} else if (enableStrictEffects && createRootStrictEffectsByDefault) {
if (isStrictMode === true || createRootStrictEffectsByDefault) {
mode |= StrictLegacyMode | StrictEffectsMode;
}
if (
Expand Down Expand Up @@ -511,7 +504,7 @@ export function createFiberFromTypeAndProps(
case REACT_STRICT_MODE_TYPE:
fiberTag = Mode;
mode |= StrictLegacyMode;
if (enableStrictEffects && (mode & ConcurrentMode) !== NoMode) {
if ((mode & ConcurrentMode) !== NoMode) {
// Strict effects should never run on legacy roots
mode |= StrictEffectsMode;
}
Expand Down
25 changes: 4 additions & 21 deletions packages/react-reconciler/src/ReactFiberClassComponent.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
enableSchedulingProfiler,
warnAboutDeprecatedLifecycles,
enableLazyContextPropagation,
enableStrictEffects,
} from 'shared/ReactFeatureFlags';
import ReactStrictModeWarnings from './ReactStrictModeWarnings.new';
import {isMounted} from './ReactFiberTreeReflection';
Expand Down Expand Up @@ -908,11 +907,7 @@ function mountClassInstance(

if (typeof instance.componentDidMount === 'function') {
let fiberFlags: Flags = Update | LayoutStatic;
if (
__DEV__ &&
enableStrictEffects &&
(workInProgress.mode & StrictEffectsMode) !== NoMode
) {
if (__DEV__ && (workInProgress.mode & StrictEffectsMode) !== NoMode) {
fiberFlags |= MountLayoutDev;
}
workInProgress.flags |= fiberFlags;
Expand Down Expand Up @@ -986,11 +981,7 @@ function resumeMountClassInstance(
// effect even though we're bailing out, so that cWU/cDU are called.
if (typeof instance.componentDidMount === 'function') {
let fiberFlags: Flags = Update | LayoutStatic;
if (
__DEV__ &&
enableStrictEffects &&
(workInProgress.mode & StrictEffectsMode) !== NoMode
) {
if (__DEV__ && (workInProgress.mode & StrictEffectsMode) !== NoMode) {
fiberFlags |= MountLayoutDev;
}
workInProgress.flags |= fiberFlags;
Expand Down Expand Up @@ -1037,11 +1028,7 @@ function resumeMountClassInstance(
}
if (typeof instance.componentDidMount === 'function') {
let fiberFlags: Flags = Update | LayoutStatic;
if (
__DEV__ &&
enableStrictEffects &&
(workInProgress.mode & StrictEffectsMode) !== NoMode
) {
if (__DEV__ && (workInProgress.mode & StrictEffectsMode) !== NoMode) {
fiberFlags |= MountLayoutDev;
}
workInProgress.flags |= fiberFlags;
Expand All @@ -1051,11 +1038,7 @@ function resumeMountClassInstance(
// effect even though we're bailing out, so that cWU/cDU are called.
if (typeof instance.componentDidMount === 'function') {
let fiberFlags: Flags = Update | LayoutStatic;
if (
__DEV__ &&
enableStrictEffects &&
(workInProgress.mode & StrictEffectsMode) !== NoMode
) {
if (__DEV__ && (workInProgress.mode & StrictEffectsMode) !== NoMode) {
fiberFlags |= MountLayoutDev;
}
workInProgress.flags |= fiberFlags;
Expand Down
25 changes: 4 additions & 21 deletions packages/react-reconciler/src/ReactFiberClassComponent.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
enableSchedulingProfiler,
warnAboutDeprecatedLifecycles,
enableLazyContextPropagation,
enableStrictEffects,
} from 'shared/ReactFeatureFlags';
import ReactStrictModeWarnings from './ReactStrictModeWarnings.old';
import {isMounted} from './ReactFiberTreeReflection';
Expand Down Expand Up @@ -908,11 +907,7 @@ function mountClassInstance(

if (typeof instance.componentDidMount === 'function') {
let fiberFlags: Flags = Update | LayoutStatic;
if (
__DEV__ &&
enableStrictEffects &&
(workInProgress.mode & StrictEffectsMode) !== NoMode
) {
if (__DEV__ && (workInProgress.mode & StrictEffectsMode) !== NoMode) {
fiberFlags |= MountLayoutDev;
}
workInProgress.flags |= fiberFlags;
Expand Down Expand Up @@ -986,11 +981,7 @@ function resumeMountClassInstance(
// effect even though we're bailing out, so that cWU/cDU are called.
if (typeof instance.componentDidMount === 'function') {
let fiberFlags: Flags = Update | LayoutStatic;
if (
__DEV__ &&
enableStrictEffects &&
(workInProgress.mode & StrictEffectsMode) !== NoMode
) {
if (__DEV__ && (workInProgress.mode & StrictEffectsMode) !== NoMode) {
fiberFlags |= MountLayoutDev;
}
workInProgress.flags |= fiberFlags;
Expand Down Expand Up @@ -1037,11 +1028,7 @@ function resumeMountClassInstance(
}
if (typeof instance.componentDidMount === 'function') {
let fiberFlags: Flags = Update | LayoutStatic;
if (
__DEV__ &&
enableStrictEffects &&
(workInProgress.mode & StrictEffectsMode) !== NoMode
) {
if (__DEV__ && (workInProgress.mode & StrictEffectsMode) !== NoMode) {
fiberFlags |= MountLayoutDev;
}
workInProgress.flags |= fiberFlags;
Expand All @@ -1051,11 +1038,7 @@ function resumeMountClassInstance(
// effect even though we're bailing out, so that cWU/cDU are called.
if (typeof instance.componentDidMount === 'function') {
let fiberFlags: Flags = Update | LayoutStatic;
if (
__DEV__ &&
enableStrictEffects &&
(workInProgress.mode & StrictEffectsMode) !== NoMode
) {
if (__DEV__ && (workInProgress.mode & StrictEffectsMode) !== NoMode) {
fiberFlags |= MountLayoutDev;
}
workInProgress.flags |= fiberFlags;
Expand Down
9 changes: 4 additions & 5 deletions packages/react-reconciler/src/ReactFiberCommitWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import {
enableCache,
enableTransitionTracing,
enableUseEventHook,
enableStrictEffects,
enableFloat,
} from 'shared/ReactFeatureFlags';
import {
Expand Down Expand Up @@ -4186,7 +4185,7 @@ function commitPassiveUnmountInsideDeletedTreeOnFiber(
}

function invokeLayoutEffectMountInDEV(fiber: Fiber): void {
if (__DEV__ && enableStrictEffects) {
if (__DEV__) {
// We don't need to re-check StrictEffectsMode here.
// This function is only called if that check has already passed.
switch (fiber.tag) {
Expand Down Expand Up @@ -4214,7 +4213,7 @@ function invokeLayoutEffectMountInDEV(fiber: Fiber): void {
}

function invokePassiveEffectMountInDEV(fiber: Fiber): void {
if (__DEV__ && enableStrictEffects) {
if (__DEV__) {
// We don't need to re-check StrictEffectsMode here.
// This function is only called if that check has already passed.
switch (fiber.tag) {
Expand All @@ -4233,7 +4232,7 @@ function invokePassiveEffectMountInDEV(fiber: Fiber): void {
}

function invokeLayoutEffectUnmountInDEV(fiber: Fiber): void {
if (__DEV__ && enableStrictEffects) {
if (__DEV__) {
// We don't need to re-check StrictEffectsMode here.
// This function is only called if that check has already passed.
switch (fiber.tag) {
Expand Down Expand Up @@ -4263,7 +4262,7 @@ function invokeLayoutEffectUnmountInDEV(fiber: Fiber): void {
}

function invokePassiveEffectUnmountInDEV(fiber: Fiber): void {
if (__DEV__ && enableStrictEffects) {
if (__DEV__) {
// We don't need to re-check StrictEffectsMode here.
// This function is only called if that check has already passed.
switch (fiber.tag) {
Expand Down
9 changes: 4 additions & 5 deletions packages/react-reconciler/src/ReactFiberCommitWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import {
enableCache,
enableTransitionTracing,
enableUseEventHook,
enableStrictEffects,
enableFloat,
} from 'shared/ReactFeatureFlags';
import {
Expand Down Expand Up @@ -4186,7 +4185,7 @@ function commitPassiveUnmountInsideDeletedTreeOnFiber(
}

function invokeLayoutEffectMountInDEV(fiber: Fiber): void {
if (__DEV__ && enableStrictEffects) {
if (__DEV__) {
// We don't need to re-check StrictEffectsMode here.
// This function is only called if that check has already passed.
switch (fiber.tag) {
Expand Down Expand Up @@ -4214,7 +4213,7 @@ function invokeLayoutEffectMountInDEV(fiber: Fiber): void {
}

function invokePassiveEffectMountInDEV(fiber: Fiber): void {
if (__DEV__ && enableStrictEffects) {
if (__DEV__) {
// We don't need to re-check StrictEffectsMode here.
// This function is only called if that check has already passed.
switch (fiber.tag) {
Expand All @@ -4233,7 +4232,7 @@ function invokePassiveEffectMountInDEV(fiber: Fiber): void {
}

function invokeLayoutEffectUnmountInDEV(fiber: Fiber): void {
if (__DEV__ && enableStrictEffects) {
if (__DEV__) {
// We don't need to re-check StrictEffectsMode here.
// This function is only called if that check has already passed.
switch (fiber.tag) {
Expand Down Expand Up @@ -4263,7 +4262,7 @@ function invokeLayoutEffectUnmountInDEV(fiber: Fiber): void {
}

function invokePassiveEffectUnmountInDEV(fiber: Fiber): void {
if (__DEV__ && enableStrictEffects) {
if (__DEV__) {
// We don't need to re-check StrictEffectsMode here.
// This function is only called if that check has already passed.
switch (fiber.tag) {
Expand Down
10 changes: 1 addition & 9 deletions packages/react-reconciler/src/ReactFiberHooks.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import {
enableUseHook,
enableUseMemoCacheHook,
enableUseEventHook,
enableStrictEffects,
} from 'shared/ReactFeatureFlags';
import {
REACT_CONTEXT_TYPE,
Expand Down Expand Up @@ -602,11 +601,7 @@ export function bailoutHooks(
workInProgress.updateQueue = current.updateQueue;
// TODO: Don't need to reset the flags here, because they're reset in the
// complete phase (bubbleProperties).
if (
__DEV__ &&
enableStrictEffects &&
(workInProgress.mode & StrictEffectsMode) !== NoMode
) {
if (__DEV__ && (workInProgress.mode & StrictEffectsMode) !== NoMode) {
workInProgress.flags &= ~(
MountPassiveDevEffect |
MountLayoutDevEffect |
Expand Down Expand Up @@ -1887,7 +1882,6 @@ function mountEffect(
): void {
if (
__DEV__ &&
enableStrictEffects &&
(currentlyRenderingFiber.mode & StrictEffectsMode) !== NoMode
) {
return mountEffectImpl(
Expand Down Expand Up @@ -1983,7 +1977,6 @@ function mountLayoutEffect(
let fiberFlags: Flags = UpdateEffect | LayoutStaticEffect;
if (
__DEV__ &&
enableStrictEffects &&
(currentlyRenderingFiber.mode & StrictEffectsMode) !== NoMode
) {
fiberFlags |= MountLayoutDevEffect;
Expand Down Expand Up @@ -2050,7 +2043,6 @@ function mountImperativeHandle<T>(
let fiberFlags: Flags = UpdateEffect | LayoutStaticEffect;
if (
__DEV__ &&
enableStrictEffects &&
(currentlyRenderingFiber.mode & StrictEffectsMode) !== NoMode
) {
fiberFlags |= MountLayoutDevEffect;
Expand Down
10 changes: 1 addition & 9 deletions packages/react-reconciler/src/ReactFiberHooks.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import {
enableUseHook,
enableUseMemoCacheHook,
enableUseEventHook,
enableStrictEffects,
} from 'shared/ReactFeatureFlags';
import {
REACT_CONTEXT_TYPE,
Expand Down Expand Up @@ -602,11 +601,7 @@ export function bailoutHooks(
workInProgress.updateQueue = current.updateQueue;
// TODO: Don't need to reset the flags here, because they're reset in the
// complete phase (bubbleProperties).
if (
__DEV__ &&
enableStrictEffects &&
(workInProgress.mode & StrictEffectsMode) !== NoMode
) {
if (__DEV__ && (workInProgress.mode & StrictEffectsMode) !== NoMode) {
workInProgress.flags &= ~(
MountPassiveDevEffect |
MountLayoutDevEffect |
Expand Down Expand Up @@ -1887,7 +1882,6 @@ function mountEffect(
): void {
if (
__DEV__ &&
enableStrictEffects &&
(currentlyRenderingFiber.mode & StrictEffectsMode) !== NoMode
) {
return mountEffectImpl(
Expand Down Expand Up @@ -1983,7 +1977,6 @@ function mountLayoutEffect(
let fiberFlags: Flags = UpdateEffect | LayoutStaticEffect;
if (
__DEV__ &&
enableStrictEffects &&
(currentlyRenderingFiber.mode & StrictEffectsMode) !== NoMode
) {
fiberFlags |= MountLayoutDevEffect;
Expand Down Expand Up @@ -2050,7 +2043,6 @@ function mountImperativeHandle<T>(
let fiberFlags: Flags = UpdateEffect | LayoutStaticEffect;
if (
__DEV__ &&
enableStrictEffects &&
(currentlyRenderingFiber.mode & StrictEffectsMode) !== NoMode
) {
fiberFlags |= MountLayoutDevEffect;
Expand Down
7 changes: 3 additions & 4 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {
enableDebugTracing,
enableSchedulingProfiler,
disableSchedulerTimeoutInWorkLoop,
enableStrictEffects,
skipUnmountedBoundaries,
enableUpdaterTracking,
enableCache,
Expand Down Expand Up @@ -2584,7 +2583,7 @@ function commitRootImpl(
legacyErrorBoundariesThatAlreadyFailed = null;
}

if (__DEV__ && enableStrictEffects) {
if (__DEV__) {
if (!rootDidHavePassiveEffects) {
commitDoubleInvokeEffectsInDEV(root, false);
}
Expand Down Expand Up @@ -2861,7 +2860,7 @@ function flushPassiveEffectsImpl() {
markPassiveEffectsStopped();
}

if (__DEV__ && enableStrictEffects) {
if (__DEV__) {
commitDoubleInvokeEffectsInDEV(root, true);
}

Expand Down Expand Up @@ -3330,7 +3329,7 @@ function commitDoubleInvokeEffectsInDEV(
root: FiberRoot,
hasPassiveEffects: boolean,
) {
if (__DEV__ && enableStrictEffects) {
if (__DEV__) {
if (useModernStrictMode) {
let doubleInvokeEffects = true;

Expand Down
Loading