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

Use the disableLegacyMode where ever we check the ConcurrentMode mode #28657

Merged
merged 6 commits into from
Apr 3, 2024
Merged
Changes from 1 commit
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
Next Next commit
Use the disableLegacyMode where ever we check the ConcurrentMode mode
  • Loading branch information
sebmarkbage committed Apr 3, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 1aba65aa0f354cdc1ca3b437b4bcc9321c6499bb
5 changes: 3 additions & 2 deletions packages/react-reconciler/src/ReactFiber.js
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@ import {
enableDebugTracing,
enableDO_NOT_USE_disableStrictPassiveEffect,
enableRenderableContext,
disableLegacyMode,
} from 'shared/ReactFeatureFlags';
import {NoFlags, Placement, StaticMask} from './ReactFiberFlags';
import {ConcurrentRoot} from './ReactRootTags';
@@ -439,7 +440,7 @@ export function createHostRootFiber(
concurrentUpdatesByDefaultOverride: null | boolean,
): Fiber {
let mode;
if (tag === ConcurrentRoot) {
if (disableLegacyMode || tag === ConcurrentRoot) {
mode = ConcurrentMode;
if (isStrictMode === true) {
mode |= StrictLegacyMode | StrictEffectsMode;
@@ -517,7 +518,7 @@ export function createFiberFromTypeAndProps(
case REACT_STRICT_MODE_TYPE:
fiberTag = Mode;
mode |= StrictLegacyMode;
if ((mode & ConcurrentMode) !== NoMode) {
if (disableLegacyMode || (mode & ConcurrentMode) !== NoMode) {
// Strict effects should never run on legacy roots
mode |= StrictEffectsMode;
if (
16 changes: 11 additions & 5 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
@@ -108,6 +108,7 @@ import {
enablePostpone,
enableRenderableContext,
enableRefAsProp,
disableLegacyMode,
} from 'shared/ReactFeatureFlags';
import isArray from 'shared/isArray';
import shallowEqual from 'shared/shallowEqual';
@@ -700,7 +701,10 @@ function updateOffscreenComponent(
);
}

if ((workInProgress.mode & ConcurrentMode) === NoMode) {
if (
!disableLegacyMode &&
(workInProgress.mode & ConcurrentMode) === NoMode
) {
// In legacy sync mode, don't defer the subtree. Render it now.
// TODO: Consider how Offscreen should work with transitions in the future
const nextState: OffscreenState = {
@@ -2347,6 +2351,7 @@ function mountSuspenseFallbackChildren(
let primaryChildFragment;
let fallbackChildFragment;
if (
!disableLegacyMode &&
(mode & ConcurrentMode) === NoMode &&
progressedPrimaryFragment !== null
) {
@@ -2430,7 +2435,7 @@ function updateSuspensePrimaryChildren(
children: primaryChildren,
},
);
if ((workInProgress.mode & ConcurrentMode) === NoMode) {
if (!disableLegacyMode && (workInProgress.mode & ConcurrentMode) === NoMode) {
primaryChildFragment.lanes = renderLanes;
}
primaryChildFragment.return = workInProgress;
@@ -2471,6 +2476,7 @@ function updateSuspenseFallbackChildren(
if (
// In legacy mode, we commit the primary tree as if it successfully
// completed, even though it's in an inconsistent state.
!disableLegacyMode &&
(mode & ConcurrentMode) === NoMode &&
// Make sure we're on the second pass, i.e. the primary child fragment was
// already cloned. In legacy mode, the only case where this isn't true is
@@ -2607,7 +2613,7 @@ function mountSuspenseFallbackAfterRetryWithoutHydrating(
primaryChildFragment.sibling = fallbackChildFragment;
workInProgress.child = primaryChildFragment;

if ((workInProgress.mode & ConcurrentMode) !== NoMode) {
if (disableLegacyMode || (workInProgress.mode & ConcurrentMode) !== NoMode) {
// We will have dropped the effect list which contains the
// deletion. We need to reconcile to delete the current child.
reconcileChildFibers(workInProgress, current.child, null, renderLanes);
@@ -3195,7 +3201,7 @@ function updateSuspenseListComponent(
}
pushSuspenseListContext(workInProgress, suspenseContext);

if ((workInProgress.mode & ConcurrentMode) === NoMode) {
if (!disableLegacyMode && (workInProgress.mode & ConcurrentMode) === NoMode) {
// In legacy mode, SuspenseList doesn't work so we just
// use make it a noop by treating it as the default revealOrder.
workInProgress.memoizedState = null;
@@ -3443,7 +3449,7 @@ function resetSuspendedCurrentOnMountInLegacyMode(
current: null | Fiber,
workInProgress: Fiber,
) {
if ((workInProgress.mode & ConcurrentMode) === NoMode) {
if (!disableLegacyMode && (workInProgress.mode & ConcurrentMode) === NoMode) {
if (current !== null) {
// A lazy component only mounts if it suspended inside a non-
// concurrent tree, in an inconsistent state. We want to treat it like
17 changes: 11 additions & 6 deletions packages/react-reconciler/src/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
@@ -54,6 +54,7 @@ import {
enableUseEffectEventHook,
enableLegacyHidden,
disableStringRefs,
disableLegacyMode,
} from 'shared/ReactFeatureFlags';
import {
FunctionComponent,
@@ -1164,7 +1165,8 @@ function commitLayoutEffectOnFiber(
break;
}
case OffscreenComponent: {
const isModernRoot = (finishedWork.mode & ConcurrentMode) !== NoMode;
const isModernRoot =
disableLegacyMode || (finishedWork.mode & ConcurrentMode) !== NoMode;
if (isModernRoot) {
const isHidden = finishedWork.memoizedState !== null;
const newOffscreenSubtreeIsHidden =
@@ -2255,7 +2257,7 @@ function commitDeletionEffectsOnFiber(
}
case OffscreenComponent: {
safelyDetachRef(deletedFiber, nearestMountedAncestor);
if (deletedFiber.mode & ConcurrentMode) {
if (disableLegacyMode || deletedFiber.mode & ConcurrentMode) {
// If this offscreen component is hidden, we already unmounted it. Before
// deleting the children, track that it's already unmounted so that we
// don't attempt to unmount the effects again.
@@ -2932,7 +2934,7 @@ function commitMutationEffectsOnFiber(
const isHidden = newState !== null;
const wasHidden = current !== null && current.memoizedState !== null;

if (finishedWork.mode & ConcurrentMode) {
if (disableLegacyMode || finishedWork.mode & ConcurrentMode) {
// Before committing the children, track on the stack whether this
// offscreen subtree was already hidden, so that we don't unmount the
// effects again.
@@ -2978,7 +2980,10 @@ function commitMutationEffectsOnFiber(
// - This Offscreen was not hidden before.
// - Ancestor Offscreen was not hidden in previous commit.
if (isUpdate && !wasHidden && !wasHiddenByAncestorOffscreen) {
if ((finishedWork.mode & ConcurrentMode) !== NoMode) {
if (
disableLegacyMode ||
(finishedWork.mode & ConcurrentMode) !== NoMode
) {
// Disappear the layout effects of all the children
recursivelyTraverseDisappearLayoutEffects(finishedWork);
}
@@ -3676,7 +3681,7 @@ function commitPassiveMountOnFiber(
committedTransitions,
);
} else {
if (finishedWork.mode & ConcurrentMode) {
if (disableLegacyMode || finishedWork.mode & ConcurrentMode) {
// The effects are currently disconnected. Since the tree is hidden,
// don't connect them. This also applies to the initial render.
if (enableCache || enableTransitionTracing) {
@@ -3874,7 +3879,7 @@ export function reconnectPassiveEffects(
includeWorkInProgressEffects,
);
} else {
if (finishedWork.mode & ConcurrentMode) {
if (disableLegacyMode || finishedWork.mode & ConcurrentMode) {
// The effects are currently disconnected. Since the tree is hidden,
// don't connect them. This also applies to the initial render.
if (enableCache || enableTransitionTracing) {
7 changes: 6 additions & 1 deletion packages/react-reconciler/src/ReactFiberCompleteWork.js
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@ import {
enableTransitionTracing,
enableRenderableContext,
passChildrenWhenCloningPersistedNodes,
disableLegacyMode,
} from 'shared/ReactFeatureFlags';

import {now} from './Scheduler';
@@ -1740,7 +1741,11 @@ function completeWork(
}
}

if (!nextIsHidden || (workInProgress.mode & ConcurrentMode) === NoMode) {
if (
!nextIsHidden ||
(!disableLegacyMode &&
(workInProgress.mode & ConcurrentMode) === NoMode)
) {
bubbleProperties(workInProgress);
} else {
// Don't bubble properties for hidden children unless we're rendering
3 changes: 2 additions & 1 deletion packages/react-reconciler/src/ReactFiberHooks.js
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@ import {
debugRenderPhaseSideEffectsForStrictMode,
enableAsyncActions,
enableUseDeferredValueInitialArg,
disableLegacyMode,
} from 'shared/ReactFeatureFlags';
import {
REACT_CONTEXT_TYPE,
@@ -662,7 +663,7 @@ function finishRenderingHooks<Props, SecondArg>(
// need to mark fibers that commit in an incomplete state, somehow. For
// now I'll disable the warning that most of the bugs that would trigger
// it are either exclusive to concurrent mode or exist in both.
(current.mode & ConcurrentMode) !== NoMode
(disableLegacyMode || (current.mode & ConcurrentMode) !== NoMode)
) {
console.error(
'Internal React error: Expected static flag was missing. Please ' +
23 changes: 17 additions & 6 deletions packages/react-reconciler/src/ReactFiberThrow.js
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@ import {
enableLazyContextPropagation,
enableUpdaterTracking,
enablePostpone,
disableLegacyMode,
} from 'shared/ReactFeatureFlags';
import {createCapturedValueAtFiber} from './ReactCapturedValue';
import {
@@ -189,6 +190,7 @@ function resetSuspendedComponent(sourceFiber: Fiber, rootRenderLanes: Lanes) {
// A legacy mode Suspense quirk, only relevant to hook components.
const tag = sourceFiber.tag;
if (
!disableLegacyMode &&
(sourceFiber.mode & ConcurrentMode) === NoMode &&
(tag === FunctionComponent ||
tag === ForwardRef ||
@@ -215,7 +217,10 @@ function markSuspenseBoundaryShouldCapture(
): Fiber | null {
// This marks a Suspense boundary so that when we're unwinding the stack,
// it captures the suspended "exception" and does a second (fallback) pass.
if ((suspenseBoundary.mode & ConcurrentMode) === NoMode) {
if (
!disableLegacyMode &&
(suspenseBoundary.mode & ConcurrentMode) === NoMode
) {
// Legacy Mode Suspense
//
// If the boundary is in legacy mode, we should *not*
@@ -354,7 +359,10 @@ function throwException(
resetSuspendedComponent(sourceFiber, rootRenderLanes);

if (__DEV__) {
if (getIsHydrating() && sourceFiber.mode & ConcurrentMode) {
if (
getIsHydrating() &&
(disableLegacyMode || sourceFiber.mode & ConcurrentMode)
) {
markDidThrowWhileHydratingDEV();
}
}
@@ -383,7 +391,7 @@ function throwException(
// we don't have to recompute it on demand. This would also allow us
// to unify with `use` which needs to perform this logic even sooner,
// before `throwException` is called.
if (sourceFiber.mode & ConcurrentMode) {
if (disableLegacyMode || sourceFiber.mode & ConcurrentMode) {
if (getShellBoundary() === null) {
// Suspended in the "shell" of the app. This is an undesirable
// loading state. We should avoid committing this tree.
@@ -451,14 +459,14 @@ function throwException(
// We only attach ping listeners in concurrent mode. Legacy
// Suspense always commits fallbacks synchronously, so there are
// no pings.
if (suspenseBoundary.mode & ConcurrentMode) {
if (disableLegacyMode || suspenseBoundary.mode & ConcurrentMode) {
attachPingListener(root, wakeable, rootRenderLanes);
}
}
return false;
}
case OffscreenComponent: {
if (suspenseBoundary.mode & ConcurrentMode) {
if (disableLegacyMode || suspenseBoundary.mode & ConcurrentMode) {
suspenseBoundary.flags |= ShouldCapture;
const isSuspenseyResource =
wakeable === noopSuspenseyCommitThenable;
@@ -522,7 +530,10 @@ function throwException(
}

// This is a regular error, not a Suspense wakeable.
if (getIsHydrating() && sourceFiber.mode & ConcurrentMode) {
if (
getIsHydrating() &&
(disableLegacyMode || sourceFiber.mode & ConcurrentMode)
) {
markDidThrowWhileHydratingDEV();
const suspenseBoundary = getSuspenseHandler();
// If the error was thrown during hydration, we may be able to recover by
9 changes: 5 additions & 4 deletions packages/react-reconciler/src/ReactFiberWorkLoop.js
Original file line number Diff line number Diff line change
@@ -602,7 +602,7 @@ export function getCurrentTime(): number {
export function requestUpdateLane(fiber: Fiber): Lane {
// Special cases
const mode = fiber.mode;
if ((mode & ConcurrentMode) === NoMode) {
if (!disableLegacyMode && (mode & ConcurrentMode) === NoMode) {
return (SyncLane: Lane);
} else if (
(executionContext & RenderContext) !== NoContext &&
@@ -669,7 +669,7 @@ function requestRetryLane(fiber: Fiber) {

// Special cases
const mode = fiber.mode;
if ((mode & ConcurrentMode) === NoMode) {
if (!disableLegacyMode && (mode & ConcurrentMode) === NoMode) {
return (SyncLane: Lane);
}

@@ -824,6 +824,7 @@ export function scheduleUpdateOnFiber(
if (
lane === SyncLane &&
executionContext === NoContext &&
!disableLegacyMode &&
(fiber.mode & ConcurrentMode) === NoMode
) {
if (__DEV__ && ReactCurrentActQueue.isBatchingLegacy) {
@@ -3794,7 +3795,7 @@ export function warnAboutUpdateOnNotYetMountedFiberInDEV(fiber: Fiber) {
return;
}

if (!(fiber.mode & ConcurrentMode)) {
if (!disableLegacyMode && !(fiber.mode & ConcurrentMode)) {
return;
}

@@ -3933,7 +3934,7 @@ function shouldForceFlushFallbacksInDEV() {

function warnIfUpdatesNotWrappedWithActDEV(fiber: Fiber): void {
if (__DEV__) {
if (fiber.mode & ConcurrentMode) {
if (disableLegacyMode || fiber.mode & ConcurrentMode) {
if (!isConcurrentActEnvironment()) {
// Not in an act environment. No need to warn.
return;