Skip to content

Commit 8b22629

Browse files
committed
Gate root.tag checks
This field is unnecessary when legacy mode is disabled.
1 parent 63cecb9 commit 8b22629

File tree

4 files changed

+36
-17
lines changed

4 files changed

+36
-17
lines changed

packages/react-reconciler/src/ReactFiberRoot.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
enableProfilerTimer,
3434
enableUpdaterTracking,
3535
enableTransitionTracing,
36+
disableLegacyMode,
3637
} from 'shared/ReactFeatureFlags';
3738
import {initializeUpdateQueue} from './ReactFiberClassUpdateQueue';
3839
import {LegacyRoot, ConcurrentRoot} from './ReactRootTags';
@@ -56,7 +57,7 @@ function FiberRootNode(
5657
onRecoverableError: any,
5758
formState: ReactFormState<any, any> | null,
5859
) {
59-
this.tag = tag;
60+
this.tag = disableLegacyMode ? ConcurrentRoot : tag;
6061
this.containerInfo = containerInfo;
6162
this.pendingChildren = null;
6263
this.current = null;
@@ -123,13 +124,18 @@ function FiberRootNode(
123124
}
124125

125126
if (__DEV__) {
126-
switch (tag) {
127-
case ConcurrentRoot:
128-
this._debugRootType = hydrate ? 'hydrateRoot()' : 'createRoot()';
129-
break;
130-
case LegacyRoot:
131-
this._debugRootType = hydrate ? 'hydrate()' : 'render()';
132-
break;
127+
if (disableLegacyMode) {
128+
// TODO: This varies by each renderer.
129+
this._debugRootType = hydrate ? 'hydrateRoot()' : 'createRoot()';
130+
} else {
131+
switch (tag) {
132+
case ConcurrentRoot:
133+
this._debugRootType = hydrate ? 'hydrateRoot()' : 'createRoot()';
134+
break;
135+
case LegacyRoot:
136+
this._debugRootType = hydrate ? 'hydrate()' : 'render()';
137+
break;
138+
}
133139
}
134140
}
135141
}

packages/react-reconciler/src/ReactFiberRootScheduler.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import type {Lane} from './ReactFiberLane';
1212
import type {PriorityLevel} from 'scheduler/src/SchedulerPriorities';
1313
import type {BatchConfigTransition} from './ReactFiberTracingMarkerComponent';
1414

15-
import {enableDeferRootSchedulingToMicrotask} from 'shared/ReactFeatureFlags';
15+
import {
16+
disableLegacyMode,
17+
enableDeferRootSchedulingToMicrotask,
18+
} from 'shared/ReactFeatureFlags';
1619
import {
1720
NoLane,
1821
NoLanes,
@@ -131,6 +134,7 @@ export function ensureRootIsScheduled(root: FiberRoot): void {
131134

132135
if (
133136
__DEV__ &&
137+
!disableLegacyMode &&
134138
ReactCurrentActQueue.isBatchingLegacy &&
135139
root.tag === LegacyRoot
136140
) {
@@ -148,7 +152,9 @@ export function flushSyncWorkOnAllRoots() {
148152
export function flushSyncWorkOnLegacyRootsOnly() {
149153
// This is allowed to be called synchronously, but the caller should check
150154
// the execution context first.
151-
flushSyncWorkAcrossRoots_impl(true);
155+
if (!disableLegacyMode) {
156+
flushSyncWorkAcrossRoots_impl(true);
157+
}
152158
}
153159

154160
function flushSyncWorkAcrossRoots_impl(onlyLegacy: boolean) {
@@ -171,7 +177,7 @@ function flushSyncWorkAcrossRoots_impl(onlyLegacy: boolean) {
171177
didPerformSomeWork = false;
172178
let root = firstScheduledRoot;
173179
while (root !== null) {
174-
if (onlyLegacy && root.tag !== LegacyRoot) {
180+
if (onlyLegacy && (disableLegacyMode || root.tag !== LegacyRoot)) {
175181
// Skip non-legacy roots.
176182
} else {
177183
const workInProgressRoot = getWorkInProgressRoot();

packages/react-reconciler/src/ReactFiberThrow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ function throwException(
497497
// No boundary was found. Unless this is a sync update, this is OK.
498498
// We can suspend and wait for more data to arrive.
499499

500-
if (root.tag === ConcurrentRoot) {
500+
if (disableLegacyMode || root.tag === ConcurrentRoot) {
501501
// In a concurrent root, suspending without a Suspense boundary is
502502
// allowed. It will suspend indefinitely without committing.
503503
//

packages/react-reconciler/src/ReactFiberWorkLoop.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,10 @@ export function performSyncWorkOnRoot(root: FiberRoot, lanes: Lanes): null {
13691369
}
13701370

13711371
let exitStatus = renderRootSync(root, lanes);
1372-
if (root.tag !== LegacyRoot && exitStatus === RootErrored) {
1372+
if (
1373+
(disableLegacyMode || root.tag !== LegacyRoot) &&
1374+
exitStatus === RootErrored
1375+
) {
13731376
// If something threw an error, try rendering one more time. We'll render
13741377
// synchronously to block concurrent data mutations, and we'll includes
13751378
// all pending updates are included. If it still fails after the second
@@ -1517,6 +1520,7 @@ export function flushSync<R>(fn: (() => R) | void): R | void {
15171520
// next event, not at the end of the previous one.
15181521
if (
15191522
rootWithPendingPassiveEffects !== null &&
1523+
!disableLegacyMode &&
15201524
rootWithPendingPassiveEffects.tag === LegacyRoot &&
15211525
(executionContext & (RenderContext | CommitContext)) === NoContext
15221526
) {
@@ -3043,7 +3047,10 @@ function commitRootImpl(
30433047
// TODO: We can optimize this by not scheduling the callback earlier. Since we
30443048
// currently schedule the callback in multiple places, will wait until those
30453049
// are consolidated.
3046-
if (includesSyncLane(pendingPassiveEffectsLanes) && root.tag !== LegacyRoot) {
3050+
if (
3051+
includesSyncLane(pendingPassiveEffectsLanes) &&
3052+
(disableLegacyMode || root.tag !== LegacyRoot)
3053+
) {
30473054
flushPassiveEffects();
30483055
}
30493056

@@ -3724,11 +3731,11 @@ function commitDoubleInvokeEffectsInDEV(
37243731
hasPassiveEffects: boolean,
37253732
) {
37263733
if (__DEV__) {
3727-
if (useModernStrictMode && root.tag !== LegacyRoot) {
3734+
if (useModernStrictMode && (disableLegacyMode || root.tag !== LegacyRoot)) {
37283735
let doubleInvokeEffects = true;
37293736

37303737
if (
3731-
root.tag === ConcurrentRoot &&
3738+
(disableLegacyMode || root.tag === ConcurrentRoot) &&
37323739
!(root.current.mode & (StrictLegacyMode | StrictEffectsMode))
37333740
) {
37343741
doubleInvokeEffects = false;
@@ -4000,7 +4007,7 @@ function warnIfUpdatesNotWrappedWithActDEV(fiber: Fiber): void {
40004007
function warnIfSuspenseResolutionNotWrappedWithActDEV(root: FiberRoot): void {
40014008
if (__DEV__) {
40024009
if (
4003-
root.tag !== LegacyRoot &&
4010+
(disableLegacyMode || root.tag !== LegacyRoot) &&
40044011
isConcurrentActEnvironment() &&
40054012
ReactCurrentActQueue.current === null
40064013
) {

0 commit comments

Comments
 (0)