Skip to content

Commit 431e76e

Browse files
committed
Switch callsites over to update lane priority
1 parent e89d74e commit 431e76e

7 files changed

+102
-216
lines changed

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

+9-10
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ import type {
1717
} from './ReactFiberHostConfig';
1818
import type {Fiber} from './ReactInternalTypes';
1919
import type {FiberRoot} from './ReactInternalTypes';
20-
import type {Lanes} from './ReactFiberLane.new';
20+
import type {LanePriority, Lanes} from './ReactFiberLane.new';
2121
import type {SuspenseState} from './ReactFiberSuspenseComponent.new';
2222
import type {UpdateQueue} from './ReactUpdateQueue.new';
2323
import type {FunctionComponentUpdateQueue} from './ReactFiberHooks.new';
2424
import type {Wakeable} from 'shared/ReactTypes';
25-
import type {ReactPriorityLevel} from './ReactInternalTypes';
2625
import type {OffscreenState} from './ReactFiberOffscreenComponent';
2726
import type {HookFlags} from './ReactHookEffectTags';
2827

@@ -1057,7 +1056,7 @@ function commitUnmount(
10571056
finishedRoot: FiberRoot,
10581057
current: Fiber,
10591058
nearestMountedAncestor: Fiber,
1060-
renderPriorityLevel: ReactPriorityLevel,
1059+
renderPriorityLevel: LanePriority,
10611060
): void {
10621061
onCommitUnmount(current);
10631062

@@ -1153,7 +1152,7 @@ function commitNestedUnmounts(
11531152
finishedRoot: FiberRoot,
11541153
root: Fiber,
11551154
nearestMountedAncestor: Fiber,
1156-
renderPriorityLevel: ReactPriorityLevel,
1155+
renderPriorityLevel: LanePriority,
11571156
): void {
11581157
// While we're inside a removed host node we don't want to call
11591158
// removeChild on the inner nodes because they're removed by the top
@@ -1463,7 +1462,7 @@ function unmountHostComponents(
14631462
finishedRoot: FiberRoot,
14641463
current: Fiber,
14651464
nearestMountedAncestor: Fiber,
1466-
renderPriorityLevel: ReactPriorityLevel,
1465+
renderPriorityLevel: LanePriority,
14671466
): void {
14681467
// We only have the top Fiber that was deleted but we need to recurse down its
14691468
// children to find all the terminal nodes.
@@ -1601,7 +1600,7 @@ function commitDeletion(
16011600
finishedRoot: FiberRoot,
16021601
current: Fiber,
16031602
nearestMountedAncestor: Fiber,
1604-
renderPriorityLevel: ReactPriorityLevel,
1603+
renderPriorityLevel: LanePriority,
16051604
): void {
16061605
if (supportsMutation) {
16071606
// Recursively delete all host nodes from the parent.
@@ -1945,7 +1944,7 @@ function commitResetTextContent(current: Fiber) {
19451944

19461945
export function commitMutationEffects(
19471946
root: FiberRoot,
1948-
renderPriorityLevel: ReactPriorityLevel,
1947+
renderPriorityLevel: LanePriority,
19491948
firstChild: Fiber,
19501949
) {
19511950
nextEffect = firstChild;
@@ -1954,7 +1953,7 @@ export function commitMutationEffects(
19541953

19551954
function commitMutationEffects_begin(
19561955
root: FiberRoot,
1957-
renderPriorityLevel: ReactPriorityLevel,
1956+
renderPriorityLevel: LanePriority,
19581957
) {
19591958
while (nextEffect !== null) {
19601959
const fiber = nextEffect;
@@ -2000,7 +1999,7 @@ function commitMutationEffects_begin(
20001999

20012000
function commitMutationEffects_complete(
20022001
root: FiberRoot,
2003-
renderPriorityLevel: ReactPriorityLevel,
2002+
renderPriorityLevel: LanePriority,
20042003
) {
20052004
while (nextEffect !== null) {
20062005
const fiber = nextEffect;
@@ -2041,7 +2040,7 @@ function commitMutationEffects_complete(
20412040
function commitMutationEffectsOnFiber(
20422041
finishedWork: Fiber,
20432042
root: FiberRoot,
2044-
renderPriorityLevel: ReactPriorityLevel,
2043+
renderPriorityLevel: LanePriority,
20452044
) {
20462045
const flags = finishedWork.flags;
20472046

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

+9-10
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ import type {
1717
} from './ReactFiberHostConfig';
1818
import type {Fiber} from './ReactInternalTypes';
1919
import type {FiberRoot} from './ReactInternalTypes';
20-
import type {Lanes} from './ReactFiberLane.old';
20+
import type {LanePriority, Lanes} from './ReactFiberLane.old';
2121
import type {SuspenseState} from './ReactFiberSuspenseComponent.old';
2222
import type {UpdateQueue} from './ReactUpdateQueue.old';
2323
import type {FunctionComponentUpdateQueue} from './ReactFiberHooks.old';
2424
import type {Wakeable} from 'shared/ReactTypes';
25-
import type {ReactPriorityLevel} from './ReactInternalTypes';
2625
import type {OffscreenState} from './ReactFiberOffscreenComponent';
2726
import type {HookFlags} from './ReactHookEffectTags';
2827

@@ -1057,7 +1056,7 @@ function commitUnmount(
10571056
finishedRoot: FiberRoot,
10581057
current: Fiber,
10591058
nearestMountedAncestor: Fiber,
1060-
renderPriorityLevel: ReactPriorityLevel,
1059+
renderPriorityLevel: LanePriority,
10611060
): void {
10621061
onCommitUnmount(current);
10631062

@@ -1153,7 +1152,7 @@ function commitNestedUnmounts(
11531152
finishedRoot: FiberRoot,
11541153
root: Fiber,
11551154
nearestMountedAncestor: Fiber,
1156-
renderPriorityLevel: ReactPriorityLevel,
1155+
renderPriorityLevel: LanePriority,
11571156
): void {
11581157
// While we're inside a removed host node we don't want to call
11591158
// removeChild on the inner nodes because they're removed by the top
@@ -1463,7 +1462,7 @@ function unmountHostComponents(
14631462
finishedRoot: FiberRoot,
14641463
current: Fiber,
14651464
nearestMountedAncestor: Fiber,
1466-
renderPriorityLevel: ReactPriorityLevel,
1465+
renderPriorityLevel: LanePriority,
14671466
): void {
14681467
// We only have the top Fiber that was deleted but we need to recurse down its
14691468
// children to find all the terminal nodes.
@@ -1601,7 +1600,7 @@ function commitDeletion(
16011600
finishedRoot: FiberRoot,
16021601
current: Fiber,
16031602
nearestMountedAncestor: Fiber,
1604-
renderPriorityLevel: ReactPriorityLevel,
1603+
renderPriorityLevel: LanePriority,
16051604
): void {
16061605
if (supportsMutation) {
16071606
// Recursively delete all host nodes from the parent.
@@ -1945,7 +1944,7 @@ function commitResetTextContent(current: Fiber) {
19451944

19461945
export function commitMutationEffects(
19471946
root: FiberRoot,
1948-
renderPriorityLevel: ReactPriorityLevel,
1947+
renderPriorityLevel: LanePriority,
19491948
firstChild: Fiber,
19501949
) {
19511950
nextEffect = firstChild;
@@ -1954,7 +1953,7 @@ export function commitMutationEffects(
19541953

19551954
function commitMutationEffects_begin(
19561955
root: FiberRoot,
1957-
renderPriorityLevel: ReactPriorityLevel,
1956+
renderPriorityLevel: LanePriority,
19581957
) {
19591958
while (nextEffect !== null) {
19601959
const fiber = nextEffect;
@@ -2000,7 +1999,7 @@ function commitMutationEffects_begin(
20001999

20012000
function commitMutationEffects_complete(
20022001
root: FiberRoot,
2003-
renderPriorityLevel: ReactPriorityLevel,
2002+
renderPriorityLevel: LanePriority,
20042003
) {
20052004
while (nextEffect !== null) {
20062005
const fiber = nextEffect;
@@ -2041,7 +2040,7 @@ function commitMutationEffects_complete(
20412040
function commitMutationEffectsOnFiber(
20422041
finishedWork: Fiber,
20432042
root: FiberRoot,
2044-
renderPriorityLevel: ReactPriorityLevel,
2043+
renderPriorityLevel: LanePriority,
20452044
) {
20462045
const flags = finishedWork.flags;
20472046

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

+13-6
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@
99

1010
import {enableProfilerTimer} from 'shared/ReactFeatureFlags';
1111

12-
import type {Fiber, FiberRoot, ReactPriorityLevel} from './ReactInternalTypes';
12+
import type {Fiber, FiberRoot} from './ReactInternalTypes';
1313
import type {ReactNodeList} from 'shared/ReactTypes';
14+
import type {LanePriority} from './ReactFiberLane.new';
1415

1516
import {DidCapture} from './ReactFiberFlags';
17+
import {
18+
lanePriorityToSchedulerPriority,
19+
NoLanePriority,
20+
} from './ReactFiberLane.new';
21+
import {NormalPriority} from './SchedulerWithReactIntegration.new';
1622

1723
declare var __REACT_DEVTOOLS_GLOBAL_HOOK__: Object | void;
1824

@@ -78,18 +84,19 @@ export function onScheduleRoot(root: FiberRoot, children: ReactNodeList) {
7884
}
7985
}
8086

81-
export function onCommitRoot(
82-
root: FiberRoot,
83-
priorityLevel: ReactPriorityLevel,
84-
) {
87+
export function onCommitRoot(root: FiberRoot, priorityLevel: LanePriority) {
8588
if (injectedHook && typeof injectedHook.onCommitFiberRoot === 'function') {
8689
try {
8790
const didError = (root.current.flags & DidCapture) === DidCapture;
8891
if (enableProfilerTimer) {
92+
const schedulerPriority =
93+
priorityLevel === NoLanePriority
94+
? NormalPriority
95+
: lanePriorityToSchedulerPriority(priorityLevel);
8996
injectedHook.onCommitFiberRoot(
9097
rendererID,
9198
root,
92-
priorityLevel,
99+
schedulerPriority,
93100
didError,
94101
);
95102
} else {

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

+13-6
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@
99

1010
import {enableProfilerTimer} from 'shared/ReactFeatureFlags';
1111

12-
import type {Fiber, FiberRoot, ReactPriorityLevel} from './ReactInternalTypes';
12+
import type {Fiber, FiberRoot} from './ReactInternalTypes';
1313
import type {ReactNodeList} from 'shared/ReactTypes';
14+
import type {LanePriority} from './ReactFiberLane.old';
1415

1516
import {DidCapture} from './ReactFiberFlags';
17+
import {
18+
lanePriorityToSchedulerPriority,
19+
NoLanePriority,
20+
} from './ReactFiberLane.old';
21+
import {NormalPriority} from './SchedulerWithReactIntegration.old';
1622

1723
declare var __REACT_DEVTOOLS_GLOBAL_HOOK__: Object | void;
1824

@@ -78,18 +84,19 @@ export function onScheduleRoot(root: FiberRoot, children: ReactNodeList) {
7884
}
7985
}
8086

81-
export function onCommitRoot(
82-
root: FiberRoot,
83-
priorityLevel: ReactPriorityLevel,
84-
) {
87+
export function onCommitRoot(root: FiberRoot, priorityLevel: LanePriority) {
8588
if (injectedHook && typeof injectedHook.onCommitFiberRoot === 'function') {
8689
try {
8790
const didError = (root.current.flags & DidCapture) === DidCapture;
8891
if (enableProfilerTimer) {
92+
const schedulerPriority =
93+
priorityLevel === NoLanePriority
94+
? NormalPriority
95+
: lanePriorityToSchedulerPriority(priorityLevel);
8996
injectedHook.onCommitFiberRoot(
9097
rendererID,
9198
root,
92-
priorityLevel,
99+
schedulerPriority,
93100
didError,
94101
);
95102
} else {

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

+29-23
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99

1010
import type {Thenable, Wakeable} from 'shared/ReactTypes';
1111
import type {Fiber, FiberRoot} from './ReactInternalTypes';
12-
import type {Lanes, Lane} from './ReactFiberLane.new';
13-
import type {ReactPriorityLevel} from './ReactInternalTypes';
12+
import type {Lanes, Lane, LanePriority} from './ReactFiberLane.new';
1413
import type {Interaction} from 'scheduler/src/Tracing';
1514
import type {SuspenseState} from './ReactFiberSuspenseComponent.new';
1615
import type {StackCursor} from './ReactFiberStack.new';
@@ -46,7 +45,6 @@ import {
4645
shouldYield,
4746
requestPaint,
4847
now,
49-
NoPriority as NoSchedulerPriority,
5048
ImmediatePriority as ImmediateSchedulerPriority,
5149
UserBlockingPriority as UserBlockingSchedulerPriority,
5250
NormalPriority as NormalSchedulerPriority,
@@ -173,6 +171,7 @@ import {
173171
markRootFinished,
174172
schedulerPriorityToLanePriority,
175173
lanePriorityToSchedulerPriority,
174+
higherLanePriority,
176175
} from './ReactFiberLane.new';
177176
import {requestCurrentTransition, NoTransition} from './ReactFiberTransition';
178177
import {beginWork as originalBeginWork} from './ReactFiberBeginWork.new';
@@ -333,7 +332,7 @@ let rootCommittingMutationOrLayoutEffects: FiberRoot | null = null;
333332

334333
let rootDoesHavePassiveEffects: boolean = false;
335334
let rootWithPendingPassiveEffects: FiberRoot | null = null;
336-
let pendingPassiveEffectsRenderPriority: ReactPriorityLevel = NoSchedulerPriority;
335+
let pendingPassiveEffectsRenderPriority: LanePriority = NoLanePriority;
337336
let pendingPassiveEffectsLanes: Lanes = NoLanes;
338337
let pendingPassiveProfilerEffects: Array<Fiber> = [];
339338

@@ -394,7 +393,7 @@ export function requestUpdateLane(fiber: Fiber): Lane {
394393
if ((mode & BlockingMode) === NoMode) {
395394
return (SyncLane: Lane);
396395
} else if ((mode & ConcurrentMode) === NoMode) {
397-
return getCurrentPriorityLevel() === ImmediateSchedulerPriority
396+
return getCurrentUpdateLanePriority() === SyncLanePriority
398397
? (SyncLane: Lane)
399398
: (SyncBatchedLane: Lane);
400399
} else if (
@@ -482,7 +481,7 @@ function requestRetryLane(fiber: Fiber) {
482481
if ((mode & BlockingMode) === NoMode) {
483482
return (SyncLane: Lane);
484483
} else if ((mode & ConcurrentMode) === NoMode) {
485-
return getCurrentPriorityLevel() === ImmediateSchedulerPriority
484+
return getCurrentUpdateLanePriority() === SyncLanePriority
486485
? (SyncLane: Lane)
487486
: (SyncBatchedLane: Lane);
488487
}
@@ -596,9 +595,9 @@ export function scheduleUpdateOnFiber(
596595
// Schedule a discrete update but only if it's not Sync.
597596
if (
598597
(executionContext & DiscreteEventContext) !== NoContext &&
599-
// Only updates at user-blocking priority or greater are considered
600-
// discrete, even inside a discrete event.
601-
updateLanePriority === InputDiscreteLanePriority
598+
// Only updates greater than default considered discrete, even inside a discrete event.
599+
higherLanePriority(updateLanePriority, DefaultLanePriority) !==
600+
DefaultLanePriority
602601
) {
603602
// This is the result of a discrete event. Track the lowest priority
604603
// discrete update per root so we can flush them early, if needed.
@@ -1751,11 +1750,17 @@ function completeUnitOfWork(unitOfWork: Fiber): void {
17511750
}
17521751

17531752
function commitRoot(root) {
1754-
const renderPriorityLevel = getCurrentPriorityLevel();
1755-
runWithPriority(
1756-
ImmediateSchedulerPriority,
1757-
commitRootImpl.bind(null, root, renderPriorityLevel),
1758-
);
1753+
const previousUpdateLanePriority = getCurrentUpdateLanePriority();
1754+
try {
1755+
setCurrentUpdateLanePriority(SyncLanePriority);
1756+
runWithPriority(
1757+
ImmediateSchedulerPriority,
1758+
commitRootImpl.bind(null, root, previousUpdateLanePriority),
1759+
);
1760+
} finally {
1761+
setCurrentUpdateLanePriority(previousUpdateLanePriority);
1762+
}
1763+
17591764
return null;
17601765
}
17611766

@@ -1983,7 +1988,10 @@ function commitRootImpl(root, renderPriorityLevel) {
19831988
rootDoesHavePassiveEffects = false;
19841989
rootWithPendingPassiveEffects = root;
19851990
pendingPassiveEffectsLanes = lanes;
1986-
pendingPassiveEffectsRenderPriority = renderPriorityLevel;
1991+
pendingPassiveEffectsRenderPriority =
1992+
renderPriorityLevel === NoLanePriority
1993+
? DefaultLanePriority
1994+
: renderPriorityLevel;
19871995
}
19881996

19891997
// Read this again, since an effect might have updated it
@@ -2097,18 +2105,16 @@ function commitRootImpl(root, renderPriorityLevel) {
20972105

20982106
export function flushPassiveEffects(): boolean {
20992107
// Returns whether passive effects were flushed.
2100-
if (pendingPassiveEffectsRenderPriority !== NoSchedulerPriority) {
2108+
if (pendingPassiveEffectsRenderPriority !== NoLanePriority) {
21012109
const priorityLevel =
2102-
pendingPassiveEffectsRenderPriority > NormalSchedulerPriority
2103-
? NormalSchedulerPriority
2110+
pendingPassiveEffectsRenderPriority > DefaultLanePriority
2111+
? DefaultLanePriority
21042112
: pendingPassiveEffectsRenderPriority;
2105-
pendingPassiveEffectsRenderPriority = NoSchedulerPriority;
2113+
pendingPassiveEffectsRenderPriority = NoLanePriority;
21062114
const previousLanePriority = getCurrentUpdateLanePriority();
21072115
try {
2108-
setCurrentUpdateLanePriority(
2109-
schedulerPriorityToLanePriority(priorityLevel),
2110-
);
2111-
return runWithPriority(priorityLevel, flushPassiveEffectsImpl);
2116+
setCurrentUpdateLanePriority(priorityLevel);
2117+
return flushPassiveEffectsImpl();
21122118
} finally {
21132119
setCurrentUpdateLanePriority(previousLanePriority);
21142120
}

0 commit comments

Comments
 (0)