Skip to content

Commit dcd1304

Browse files
authored
Use Lane to track root callback priority (#21089)
Instead of LanePriority. I'm removing all uses of LanePriority so I can delete it.
1 parent 5f21a9f commit dcd1304

7 files changed

Lines changed: 68 additions & 114 deletions

File tree

‎packages/react-reconciler/src/ReactFiberLane.new.js‎

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
importtype{FiberRoot,ReactPriorityLevel}from'./ReactInternalTypes';
10+
importtype{FiberRoot}from'./ReactInternalTypes';
1111

1212
// TODO: Ideally these types would be opaque but that doesn't work well with
1313
// our reconciler fork infra, since these leak into non-reconciler packages.
@@ -35,17 +35,8 @@ export type Lanes = number;
3535
exporttypeLane=number;
3636
exporttypeLaneMap<T>=Array<T>;
3737

38-
importinvariantfrom'shared/invariant';
3938
import{enableCache,enableSchedulingProfiler}from'shared/ReactFeatureFlags';
4039

41-
import{
42-
ImmediatePriorityasImmediateSchedulerPriority,
43-
UserBlockingPriorityasUserBlockingSchedulerPriority,
44-
NormalPriorityasNormalSchedulerPriority,
45-
IdlePriorityasIdleSchedulerPriority,
46-
NoPriorityasNoSchedulerPriority,
47-
}from'./SchedulerWithReactIntegration.new';
48-
4940
exportconstSyncLanePriority: LanePriority=12;
5041

5142
constInputContinuousHydrationLanePriority: LanePriority=11;
@@ -244,37 +235,6 @@ function getHighestPriorityLanes(lanes: Lanes | Lane): Lanes {
244235
}
245236
}
246237

247-
exportfunctionlanePriorityToSchedulerPriority(
248-
lanePriority: LanePriority,
249-
): ReactPriorityLevel{
250-
switch(lanePriority){
251-
caseSyncLanePriority:
252-
returnImmediateSchedulerPriority;
253-
caseInputContinuousHydrationLanePriority:
254-
caseInputContinuousLanePriority:
255-
returnUserBlockingSchedulerPriority;
256-
caseDefaultHydrationLanePriority:
257-
caseDefaultLanePriority:
258-
caseTransitionHydrationPriority:
259-
caseTransitionPriority:
260-
caseSelectiveHydrationLanePriority:
261-
caseRetryLanePriority:
262-
returnNormalSchedulerPriority;
263-
caseIdleHydrationLanePriority:
264-
caseIdleLanePriority:
265-
caseOffscreenLanePriority:
266-
returnIdleSchedulerPriority;
267-
caseNoLanePriority:
268-
returnNoSchedulerPriority;
269-
default:
270-
invariant(
271-
false,
272-
'Invalid update priority: %s. This is a bug in React.',
273-
lanePriority,
274-
);
275-
}
276-
}
277-
278238
exportfunctiongetNextLanes(root: FiberRoot,wipLanes: Lanes): Lanes{
279239
// Early bailout if there's no pending work left.
280240
constpendingLanes=root.pendingLanes;

‎packages/react-reconciler/src/ReactFiberLane.old.js‎

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
importtype{FiberRoot,ReactPriorityLevel}from'./ReactInternalTypes';
10+
importtype{FiberRoot}from'./ReactInternalTypes';
1111

1212
// TODO: Ideally these types would be opaque but that doesn't work well with
1313
// our reconciler fork infra, since these leak into non-reconciler packages.
@@ -35,17 +35,8 @@ export type Lanes = number;
3535
exporttypeLane=number;
3636
exporttypeLaneMap<T>=Array<T>;
3737

38-
importinvariantfrom'shared/invariant';
3938
import{enableCache,enableSchedulingProfiler}from'shared/ReactFeatureFlags';
4039

41-
import{
42-
ImmediatePriorityasImmediateSchedulerPriority,
43-
UserBlockingPriorityasUserBlockingSchedulerPriority,
44-
NormalPriorityasNormalSchedulerPriority,
45-
IdlePriorityasIdleSchedulerPriority,
46-
NoPriorityasNoSchedulerPriority,
47-
}from'./SchedulerWithReactIntegration.old';
48-
4940
exportconstSyncLanePriority: LanePriority=12;
5041

5142
constInputContinuousHydrationLanePriority: LanePriority=11;
@@ -244,37 +235,6 @@ function getHighestPriorityLanes(lanes: Lanes | Lane): Lanes {
244235
}
245236
}
246237

247-
exportfunctionlanePriorityToSchedulerPriority(
248-
lanePriority: LanePriority,
249-
): ReactPriorityLevel{
250-
switch(lanePriority){
251-
caseSyncLanePriority:
252-
returnImmediateSchedulerPriority;
253-
caseInputContinuousHydrationLanePriority:
254-
caseInputContinuousLanePriority:
255-
returnUserBlockingSchedulerPriority;
256-
caseDefaultHydrationLanePriority:
257-
caseDefaultLanePriority:
258-
caseTransitionHydrationPriority:
259-
caseTransitionPriority:
260-
caseSelectiveHydrationLanePriority:
261-
caseRetryLanePriority:
262-
returnNormalSchedulerPriority;
263-
caseIdleHydrationLanePriority:
264-
caseIdleLanePriority:
265-
caseOffscreenLanePriority:
266-
returnIdleSchedulerPriority;
267-
caseNoLanePriority:
268-
returnNoSchedulerPriority;
269-
default:
270-
invariant(
271-
false,
272-
'Invalid update priority: %s. This is a bug in React.',
273-
lanePriority,
274-
);
275-
}
276-
}
277-
278238
exportfunctiongetNextLanes(root: FiberRoot,wipLanes: Lanes): Lanes{
279239
// Early bailout if there's no pending work left.
280240
constpendingLanes=root.pendingLanes;

‎packages/react-reconciler/src/ReactFiberRoot.new.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import type {RootTag} from './ReactRootTags';
1313
import{noTimeout,supportsHydration}from'./ReactFiberHostConfig';
1414
import{createHostRootFiber}from'./ReactFiber.new';
1515
import{
16+
NoLane,
1617
NoLanes,
17-
NoLanePriority,
1818
NoTimestamp,
1919
createLaneMap,
2020
}from'./ReactFiberLane.new';
@@ -41,7 +41,7 @@ function FiberRootNode(containerInfo, tag, hydrate) {
4141
this.pendingContext=null;
4242
this.hydrate=hydrate;
4343
this.callbackNode=null;
44-
this.callbackPriority=NoLanePriority;
44+
this.callbackPriority=NoLane;
4545
this.eventTimes=createLaneMap(NoLanes);
4646
this.expirationTimes=createLaneMap(NoTimestamp);
4747

‎packages/react-reconciler/src/ReactFiberRoot.old.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import type {RootTag} from './ReactRootTags';
1313
import{noTimeout,supportsHydration}from'./ReactFiberHostConfig';
1414
import{createHostRootFiber}from'./ReactFiber.old';
1515
import{
16+
NoLane,
1617
NoLanes,
17-
NoLanePriority,
1818
NoTimestamp,
1919
createLaneMap,
2020
}from'./ReactFiberLane.old';
@@ -41,7 +41,7 @@ function FiberRootNode(containerInfo, tag, hydrate) {
4141
this.pendingContext=null;
4242
this.hydrate=hydrate;
4343
this.callbackNode=null;
44-
this.callbackPriority=NoLanePriority;
44+
this.callbackPriority=NoLane;
4545
this.eventTimes=createLaneMap(NoLanes);
4646
this.expirationTimes=createLaneMap(NoTimestamp);
4747

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

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ import {
4343
requestPaint,
4444
now,
4545
ImmediatePriorityasImmediateSchedulerPriority,
46+
UserBlockingPriorityasUserBlockingSchedulerPriority,
4647
NormalPriorityasNormalSchedulerPriority,
48+
IdlePriorityasIdleSchedulerPriority,
4749
flushSyncCallbackQueue,
4850
scheduleSyncCallback,
4951
}from'./SchedulerWithReactIntegration.new';
@@ -130,8 +132,6 @@ import {
130132
MountLayoutDev,
131133
}from'./ReactFiberFlags';
132134
import{
133-
NoLanePriority,
134-
SyncLanePriority,
135135
NoLanes,
136136
NoLane,
137137
SyncLane,
@@ -147,7 +147,6 @@ import {
147147
includesOnlyRetries,
148148
includesOnlyTransitions,
149149
getNextLanes,
150-
returnNextLanesPriority,
151150
markStarvedLanesAsExpired,
152151
getLanesToRetrySynchronouslyOnError,
153152
getMostRecentEventTime,
@@ -156,12 +155,14 @@ import {
156155
markRootPinged,
157156
markRootExpired,
158157
markRootFinished,
159-
lanePriorityToSchedulerPriority,
160158
areLanesExpired,
159+
getHighestPriorityLane,
161160
}from'./ReactFiberLane.new';
162161
import{
163162
DiscreteEventPriority,
163+
ContinuousEventPriority,
164164
DefaultEventPriority,
165+
IdleEventPriority,
165166
getCurrentUpdatePriority,
166167
setCurrentUpdatePriority,
167168
higherEventPriority,
@@ -653,19 +654,20 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
653654
root,
654655
root===workInProgressRoot ? workInProgressRootRenderLanes : NoLanes,
655656
);
656-
// This returns the priority level computed during the `getNextLanes` call.
657-
constnewCallbackPriority=returnNextLanesPriority();
658657

659658
if(nextLanes===NoLanes){
660659
// Special case: There's nothing to work on.
661660
if(existingCallbackNode!==null){
662661
cancelCallback(existingCallbackNode);
663662
}
664663
root.callbackNode =null;
665-
root.callbackPriority=NoLanePriority;
664+
root.callbackPriority=NoLane;
666665
return;
667666
}
668667

668+
// We use the highest priority lane to represent the priority of the callback.
669+
constnewCallbackPriority=getHighestPriorityLane(nextLanes);
670+
669671
// Check if there's an existing task. We may be able to reuse it.
670672
constexistingCallbackPriority=root.callbackPriority;
671673
if(existingCallbackPriority===newCallbackPriority){
@@ -675,7 +677,7 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
675677
// TODO: Temporary until we confirm this warning is not fired.
676678
if(
677679
existingCallbackNode==null&&
678-
existingCallbackPriority!==SyncLanePriority
680+
existingCallbackPriority!==SyncLane
679681
){
680682
console.error(
681683
'Expected scheduled callback to exist. This error is likely caused by a bug in React. Please file an issue.',
@@ -693,7 +695,7 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
693695

694696
// Schedule a new callback.
695697
let newCallbackNode;
696-
if (newCallbackPriority === SyncLanePriority) {
698+
if (newCallbackPriority === SyncLane) {
697699
// Special case: Sync React callbacks are scheduled on a special
698700
// internal queue
699701
scheduleSyncCallback(performSyncWorkOnRoot.bind(null,root));
@@ -706,9 +708,24 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
706708
}
707709
newCallbackNode = null;
708710
}else{
709-
constschedulerPriorityLevel=lanePriorityToSchedulerPriority(
710-
newCallbackPriority,
711-
);
711+
letschedulerPriorityLevel;
712+
switch(lanesToEventPriority(nextLanes)){
713+
caseDiscreteEventPriority:
714+
schedulerPriorityLevel=ImmediateSchedulerPriority;
715+
break;
716+
caseContinuousEventPriority:
717+
schedulerPriorityLevel=UserBlockingSchedulerPriority;
718+
break;
719+
caseDefaultEventPriority:
720+
schedulerPriorityLevel=NormalSchedulerPriority;
721+
break;
722+
caseIdleEventPriority:
723+
schedulerPriorityLevel=IdleSchedulerPriority;
724+
break;
725+
default:
726+
schedulerPriorityLevel=NormalSchedulerPriority;
727+
break;
728+
}
712729
newCallbackNode = scheduleCallback(
713730
schedulerPriorityLevel,
714731
performConcurrentWorkOnRoot.bind(null, root),
@@ -1744,7 +1761,7 @@ function commitRootImpl(root, renderPriorityLevel) {
17441761
// commitRoot never returns a continuation; it always finishes synchronously.
17451762
// So we can clear these now to allow a new callback to be scheduled.
17461763
root.callbackNode=null;
1747-
root.callbackPriority=NoLanePriority;
1764+
root.callbackPriority=NoLane;
17481765

17491766
// Update the first and last pending times on this root. The new first
17501767
// pending time is whatever is left on the root fiber.

0 commit comments

Comments
 (0)