@@ -24,6 +24,28 @@ import {
24
24
} from 'shared/ReactFeatureFlags' ;
25
25
import { isDevToolsPresent } from './ReactFiberDevToolsHook.new' ;
26
26
27
+ export const SyncLanePriority : LanePriority = 12 ;
28
+
29
+ const InputContinuousHydrationLanePriority : LanePriority = 11 ;
30
+ export const InputContinuousLanePriority : LanePriority = 10 ;
31
+
32
+ const DefaultHydrationLanePriority : LanePriority = 9 ;
33
+ export const DefaultLanePriority : LanePriority = 8 ;
34
+
35
+ const TransitionHydrationPriority : LanePriority = 7 ;
36
+ export const TransitionPriority : LanePriority = 6 ;
37
+
38
+ const RetryLanePriority : LanePriority = 5 ;
39
+
40
+ const SelectiveHydrationLanePriority : LanePriority = 4 ;
41
+
42
+ const IdleHydrationLanePriority : LanePriority = 3 ;
43
+ export const IdleLanePriority : LanePriority = 2 ;
44
+
45
+ const OffscreenLanePriority : LanePriority = 1 ;
46
+
47
+ export const NoLanePriority : LanePriority = 0 ;
48
+
27
49
// Lane values below should be kept in sync with getLabelsForLanes(), used by react-devtools-scheduling-profiler.
28
50
// If those values are changed that package should be rebuilt and redeployed.
29
51
@@ -127,19 +149,29 @@ export const NoTimestamp = -1;
127
149
let nextTransitionLane : Lane = TransitionLane1 ;
128
150
let nextRetryLane : Lane = RetryLane1 ;
129
151
152
+ // "Registers" used to "return" multiple values
153
+ // Used by getHighestPriorityLanes and getNextLanes:
154
+ let return_highestLanePriority : LanePriority = DefaultLanePriority ;
155
+
130
156
function getHighestPriorityLanes ( lanes : Lanes | Lane ) : Lanes {
131
157
switch ( getHighestPriorityLane ( lanes ) ) {
132
158
case SyncLane:
159
+ return_highestLanePriority = SyncLanePriority ;
133
160
return SyncLane ;
134
161
case InputContinuousHydrationLane:
162
+ return_highestLanePriority = InputContinuousHydrationLanePriority ;
135
163
return InputContinuousHydrationLane ;
136
164
case InputContinuousLane:
165
+ return_highestLanePriority = InputContinuousLanePriority ;
137
166
return InputContinuousLane ;
138
167
case DefaultHydrationLane:
168
+ return_highestLanePriority = DefaultHydrationLanePriority ;
139
169
return DefaultHydrationLane ;
140
170
case DefaultLane:
171
+ return_highestLanePriority = DefaultLanePriority ;
141
172
return DefaultLane ;
142
173
case TransitionHydrationLane:
174
+ return_highestLanePriority = TransitionHydrationPriority ;
143
175
return TransitionHydrationLane ;
144
176
case TransitionLane1:
145
177
case TransitionLane2:
@@ -157,20 +189,26 @@ function getHighestPriorityLanes(lanes: Lanes | Lane): Lanes {
157
189
case TransitionLane14:
158
190
case TransitionLane15:
159
191
case TransitionLane16:
192
+ return_highestLanePriority = TransitionPriority ;
160
193
return lanes & TransitionLanes ;
161
194
case RetryLane1 :
162
195
case RetryLane2:
163
196
case RetryLane3:
164
197
case RetryLane4:
165
198
case RetryLane5:
199
+ return_highestLanePriority = RetryLanePriority ;
166
200
return lanes & RetryLanes ;
167
201
case SelectiveHydrationLane:
202
+ return_highestLanePriority = SelectiveHydrationLanePriority ;
168
203
return SelectiveHydrationLane ;
169
204
case IdleHydrationLane:
205
+ return_highestLanePriority = IdleHydrationLanePriority ;
170
206
return IdleHydrationLane ;
171
207
case IdleLane :
208
+ return_highestLanePriority = IdleLanePriority ;
172
209
return IdleLane ;
173
210
case OffscreenLane:
211
+ return_highestLanePriority = OffscreenLanePriority ;
174
212
return OffscreenLane ;
175
213
default:
176
214
if ( __DEV__ ) {
@@ -179,6 +217,7 @@ function getHighestPriorityLanes(lanes: Lanes | Lane): Lanes {
179
217
) ;
180
218
}
181
219
// This shouldn't be reachable, but as a fallback, return the entire bitmask.
220
+ return_highestLanePriority = DefaultLanePriority ;
182
221
return lanes ;
183
222
}
184
223
}
@@ -187,10 +226,12 @@ export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes {
187
226
// Early bailout if there's no pending work left.
188
227
const pendingLanes = root . pendingLanes ;
189
228
if ( pendingLanes === NoLanes ) {
229
+ return_highestLanePriority = NoLanePriority ;
190
230
return NoLanes ;
191
231
}
192
232
193
233
let nextLanes = NoLanes ;
234
+ let nextLanePriority = NoLanePriority ;
194
235
195
236
const suspendedLanes = root . suspendedLanes ;
196
237
const pingedLanes = root . pingedLanes ;
@@ -202,20 +243,24 @@ export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes {
202
243
const nonIdleUnblockedLanes = nonIdlePendingLanes & ~ suspendedLanes ;
203
244
if ( nonIdleUnblockedLanes !== NoLanes ) {
204
245
nextLanes = getHighestPriorityLanes ( nonIdleUnblockedLanes ) ;
246
+ nextLanePriority = return_highestLanePriority ;
205
247
} else {
206
248
const nonIdlePingedLanes = nonIdlePendingLanes & pingedLanes ;
207
249
if ( nonIdlePingedLanes !== NoLanes ) {
208
250
nextLanes = getHighestPriorityLanes ( nonIdlePingedLanes ) ;
251
+ nextLanePriority = return_highestLanePriority ;
209
252
}
210
253
}
211
254
} else {
212
255
// The only remaining work is Idle.
213
256
const unblockedLanes = pendingLanes & ~ suspendedLanes ;
214
257
if ( unblockedLanes !== NoLanes ) {
215
258
nextLanes = getHighestPriorityLanes ( unblockedLanes ) ;
259
+ nextLanePriority = return_highestLanePriority ;
216
260
} else {
217
261
if ( pingedLanes !== NoLanes ) {
218
262
nextLanes = getHighestPriorityLanes ( pingedLanes ) ;
263
+ nextLanePriority = return_highestLanePriority ;
219
264
}
220
265
}
221
266
}
@@ -249,6 +294,8 @@ export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes {
249
294
) {
250
295
// Keep working on the existing in-progress tree. Do not interrupt.
251
296
return wipLanes ;
297
+ } else {
298
+ return_highestLanePriority = nextLanePriority ;
252
299
}
253
300
}
254
301
@@ -443,6 +490,9 @@ export function getLanesToRetrySynchronouslyOnError(root: FiberRoot): Lanes {
443
490
return NoLanes ;
444
491
}
445
492
493
+ export function returnNextLanesPriority ( ) {
494
+ return return_highestLanePriority ;
495
+ }
446
496
export function includesNonIdleWork ( lanes : Lanes ) {
447
497
return ( lanes & NonIdleLanes ) !== NoLanes ;
448
498
}
@@ -548,6 +598,13 @@ export function higherPriorityLane(a: Lane, b: Lane) {
548
598
return a !== NoLane && a < b ? a : b ;
549
599
}
550
600
601
+ export function higherLanePriority (
602
+ a : LanePriority ,
603
+ b : LanePriority ,
604
+ ) : LanePriority {
605
+ return a !== NoLanePriority && a > b ? a : b ;
606
+ }
607
+
551
608
export function createLaneMap < T > (initial: T): LaneMap< T > {
552
609
// Intentionally pushing one by one.
553
610
// https://v8.dev/blog/elements-kinds#avoid-creating-holes
0 commit comments