Skip to content

Commit

Permalink
Gate root.tag checks
Browse files Browse the repository at this point in the history
This field is unnecessary when legacy mode is disabled.
  • Loading branch information
sebmarkbage committed Apr 2, 2024
1 parent 63cecb9 commit 8b22629
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
22 changes: 14 additions & 8 deletions packages/react-reconciler/src/ReactFiberRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
enableProfilerTimer,
enableUpdaterTracking,
enableTransitionTracing,
disableLegacyMode,
} from 'shared/ReactFeatureFlags';
import {initializeUpdateQueue} from './ReactFiberClassUpdateQueue';
import {LegacyRoot, ConcurrentRoot} from './ReactRootTags';
Expand All @@ -56,7 +57,7 @@ function FiberRootNode(
onRecoverableError: any,
formState: ReactFormState<any, any> | null,
) {
this.tag = tag;
this.tag = disableLegacyMode ? ConcurrentRoot : tag;
this.containerInfo = containerInfo;
this.pendingChildren = null;
this.current = null;
Expand Down Expand Up @@ -123,13 +124,18 @@ function FiberRootNode(
}

if (__DEV__) {
switch (tag) {
case ConcurrentRoot:
this._debugRootType = hydrate ? 'hydrateRoot()' : 'createRoot()';
break;
case LegacyRoot:
this._debugRootType = hydrate ? 'hydrate()' : 'render()';
break;
if (disableLegacyMode) {
// TODO: This varies by each renderer.
this._debugRootType = hydrate ? 'hydrateRoot()' : 'createRoot()';
} else {
switch (tag) {
case ConcurrentRoot:
this._debugRootType = hydrate ? 'hydrateRoot()' : 'createRoot()';
break;
case LegacyRoot:
this._debugRootType = hydrate ? 'hydrate()' : 'render()';
break;
}
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions packages/react-reconciler/src/ReactFiberRootScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import type {Lane} from './ReactFiberLane';
import type {PriorityLevel} from 'scheduler/src/SchedulerPriorities';
import type {BatchConfigTransition} from './ReactFiberTracingMarkerComponent';

import {enableDeferRootSchedulingToMicrotask} from 'shared/ReactFeatureFlags';
import {
disableLegacyMode,
enableDeferRootSchedulingToMicrotask,
} from 'shared/ReactFeatureFlags';
import {
NoLane,
NoLanes,
Expand Down Expand Up @@ -131,6 +134,7 @@ export function ensureRootIsScheduled(root: FiberRoot): void {

if (
__DEV__ &&
!disableLegacyMode &&
ReactCurrentActQueue.isBatchingLegacy &&
root.tag === LegacyRoot
) {
Expand All @@ -148,7 +152,9 @@ export function flushSyncWorkOnAllRoots() {
export function flushSyncWorkOnLegacyRootsOnly() {
// This is allowed to be called synchronously, but the caller should check
// the execution context first.
flushSyncWorkAcrossRoots_impl(true);
if (!disableLegacyMode) {
flushSyncWorkAcrossRoots_impl(true);
}
}

function flushSyncWorkAcrossRoots_impl(onlyLegacy: boolean) {
Expand All @@ -171,7 +177,7 @@ function flushSyncWorkAcrossRoots_impl(onlyLegacy: boolean) {
didPerformSomeWork = false;
let root = firstScheduledRoot;
while (root !== null) {
if (onlyLegacy && root.tag !== LegacyRoot) {
if (onlyLegacy && (disableLegacyMode || root.tag !== LegacyRoot)) {
// Skip non-legacy roots.
} else {
const workInProgressRoot = getWorkInProgressRoot();
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberThrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ function throwException(
// No boundary was found. Unless this is a sync update, this is OK.
// We can suspend and wait for more data to arrive.

if (root.tag === ConcurrentRoot) {
if (disableLegacyMode || root.tag === ConcurrentRoot) {
// In a concurrent root, suspending without a Suspense boundary is
// allowed. It will suspend indefinitely without committing.
//
Expand Down
17 changes: 12 additions & 5 deletions packages/react-reconciler/src/ReactFiberWorkLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,10 @@ export function performSyncWorkOnRoot(root: FiberRoot, lanes: Lanes): null {
}

let exitStatus = renderRootSync(root, lanes);
if (root.tag !== LegacyRoot && exitStatus === RootErrored) {
if (
(disableLegacyMode || root.tag !== LegacyRoot) &&
exitStatus === RootErrored
) {
// If something threw an error, try rendering one more time. We'll render
// synchronously to block concurrent data mutations, and we'll includes
// all pending updates are included. If it still fails after the second
Expand Down Expand Up @@ -1517,6 +1520,7 @@ export function flushSync<R>(fn: (() => R) | void): R | void {
// next event, not at the end of the previous one.
if (
rootWithPendingPassiveEffects !== null &&
!disableLegacyMode &&
rootWithPendingPassiveEffects.tag === LegacyRoot &&
(executionContext & (RenderContext | CommitContext)) === NoContext
) {
Expand Down Expand Up @@ -3043,7 +3047,10 @@ function commitRootImpl(
// TODO: We can optimize this by not scheduling the callback earlier. Since we
// currently schedule the callback in multiple places, will wait until those
// are consolidated.
if (includesSyncLane(pendingPassiveEffectsLanes) && root.tag !== LegacyRoot) {
if (
includesSyncLane(pendingPassiveEffectsLanes) &&
(disableLegacyMode || root.tag !== LegacyRoot)
) {
flushPassiveEffects();
}

Expand Down Expand Up @@ -3724,11 +3731,11 @@ function commitDoubleInvokeEffectsInDEV(
hasPassiveEffects: boolean,
) {
if (__DEV__) {
if (useModernStrictMode && root.tag !== LegacyRoot) {
if (useModernStrictMode && (disableLegacyMode || root.tag !== LegacyRoot)) {
let doubleInvokeEffects = true;

if (
root.tag === ConcurrentRoot &&
(disableLegacyMode || root.tag === ConcurrentRoot) &&
!(root.current.mode & (StrictLegacyMode | StrictEffectsMode))
) {
doubleInvokeEffects = false;
Expand Down Expand Up @@ -4000,7 +4007,7 @@ function warnIfUpdatesNotWrappedWithActDEV(fiber: Fiber): void {
function warnIfSuspenseResolutionNotWrappedWithActDEV(root: FiberRoot): void {
if (__DEV__) {
if (
root.tag !== LegacyRoot &&
(disableLegacyMode || root.tag !== LegacyRoot) &&
isConcurrentActEnvironment() &&
ReactCurrentActQueue.current === null
) {
Expand Down

0 comments on commit 8b22629

Please sign in to comment.