Revert "Delete LanePriority type (#21090)"
This reverts commit 26ddc63f2dcc8e7dcbacf498237a2bb1e28a7d23. No longer using LanePriority anywhere, so this deletes the remaining references.
Andrew Clark committed
Apr 23, 2021 at 11:50 UTC
1bd41c6645af83d537e5b9c2b50ec076c1c5b315
2 files changed
+152
packages/react-reconciler/src/ReactFiberLane.new.js
+76
@@ -11,6 +11,25 @@ import type {FiberRoot} from './ReactInternalTypes';
11
12
// TODO: Ideally these types would be opaque but that doesn't work well with
13
// our reconciler fork infra, since these leak into non-reconciler packages.
14
+export type LanePriority =
15
+ | 0
16
+ | 1
17
+ | 2
18
+ | 3
19
+ | 4
20
+ | 5
21
+ | 6
22
+ | 7
23
+ | 8
24
+ | 9
25
+ | 10
26
+ | 11
27
+ | 12
28
+ | 13
29
+ | 14
30
+ | 15
31
+ | 16
32
+ | 17;
33
34
export type Lanes = number;
35
export type Lane = number;
@@ -24,6 +43,28 @@ import {
43
} from 'shared/ReactFeatureFlags';
44
import {isDevToolsPresent} from './ReactFiberDevToolsHook.new';
45
46
+export const SyncLanePriority: LanePriority = 12;
47
+
48
+const InputContinuousHydrationLanePriority: LanePriority = 11;
49
+export const InputContinuousLanePriority: LanePriority = 10;
50
+
51
+const DefaultHydrationLanePriority: LanePriority = 9;
52
+export const DefaultLanePriority: LanePriority = 8;
53
+
54
+const TransitionHydrationPriority: LanePriority = 7;
55
+export const TransitionPriority: LanePriority = 6;
56
+
57
+const RetryLanePriority: LanePriority = 5;
58
+
59
+const SelectiveHydrationLanePriority: LanePriority = 4;
60
+
61
+const IdleHydrationLanePriority: LanePriority = 3;
62
+export const IdleLanePriority: LanePriority = 2;
63
+
64
+const OffscreenLanePriority: LanePriority = 1;
65
+
66
+export const NoLanePriority: LanePriority = 0;
67
+
68
// Lane values below should be kept in sync with getLabelsForLanes(), used by react-devtools-scheduling-profiler.
69
// If those values are changed that package should be rebuilt and redeployed.
70
@@ -127,19 +168,29 @@ export const NoTimestamp = -1;
168
let nextTransitionLane: Lane = TransitionLane1;
169
let nextRetryLane: Lane = RetryLane1;
170
171
+// "Registers" used to "return" multiple values
172
+// Used by getHighestPriorityLanes and getNextLanes:
173
+let return_highestLanePriority: LanePriority = DefaultLanePriority;
174
+
175
function getHighestPriorityLanes(lanes: Lanes | Lane): Lanes {
176
switch (getHighestPriorityLane(lanes)) {
177
case SyncLane:
178
+ return_highestLanePriority = SyncLanePriority;
179
return SyncLane;
180
case InputContinuousHydrationLane:
181
+ return_highestLanePriority = InputContinuousHydrationLanePriority;
182
return InputContinuousHydrationLane;
183
case InputContinuousLane:
184
+ return_highestLanePriority = InputContinuousLanePriority;
185
return InputContinuousLane;
186
case DefaultHydrationLane:
187
+ return_highestLanePriority = DefaultHydrationLanePriority;
188
return DefaultHydrationLane;
189
case DefaultLane:
190
+ return_highestLanePriority = DefaultLanePriority;
191
return DefaultLane;
192
case TransitionHydrationLane:
193
+ return_highestLanePriority = TransitionHydrationPriority;
194
return TransitionHydrationLane;
195
case TransitionLane1:
196
case TransitionLane2:
@@ -157,20 +208,26 @@ function getHighestPriorityLanes(lanes: Lanes | Lane): Lanes {
208
case TransitionLane14:
209
case TransitionLane15:
210
case TransitionLane16:
211
+ return_highestLanePriority = TransitionPriority;
212
return lanes & TransitionLanes;
213
case RetryLane1:
214
case RetryLane2:
215
case RetryLane3:
216
case RetryLane4:
217
case RetryLane5:
218
+ return_highestLanePriority = RetryLanePriority;
219
return lanes & RetryLanes;
220
case SelectiveHydrationLane:
221
+ return_highestLanePriority = SelectiveHydrationLanePriority;
222
return SelectiveHydrationLane;
223
case IdleHydrationLane:
224
+ return_highestLanePriority = IdleHydrationLanePriority;
225
return IdleHydrationLane;
226
case IdleLane:
227
+ return_highestLanePriority = IdleLanePriority;
228
return IdleLane;
229
case OffscreenLane:
230
+ return_highestLanePriority = OffscreenLanePriority;
231
return OffscreenLane;
232
default:
233
if (__DEV__) {
@@ -179,6 +236,7 @@ function getHighestPriorityLanes(lanes: Lanes | Lane): Lanes {
236
);
237
}
238
// This shouldn't be reachable, but as a fallback, return the entire bitmask.
239
+ return_highestLanePriority = DefaultLanePriority;
240
return lanes;
241
}
242
}
@@ -187,10 +245,12 @@ export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes {
245
// Early bailout if there's no pending work left.
246
const pendingLanes = root.pendingLanes;
247
if (pendingLanes === NoLanes) {
248
+ return_highestLanePriority = NoLanePriority;
249
return NoLanes;
250
}
251
252
let nextLanes = NoLanes;
253
+ let nextLanePriority = NoLanePriority;
254
255
const suspendedLanes = root.suspendedLanes;
256
const pingedLanes = root.pingedLanes;
@@ -202,10 +262,12 @@ export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes {
262
const nonIdleUnblockedLanes = nonIdlePendingLanes & ~suspendedLanes;
263
if (nonIdleUnblockedLanes !== NoLanes) {
264
nextLanes = getHighestPriorityLanes(nonIdleUnblockedLanes);
265
+ nextLanePriority = return_highestLanePriority;
266
} else {
267
const nonIdlePingedLanes = nonIdlePendingLanes & pingedLanes;
268
if (nonIdlePingedLanes !== NoLanes) {
269
nextLanes = getHighestPriorityLanes(nonIdlePingedLanes);
270
+ nextLanePriority = return_highestLanePriority;
271
}
272
}
273
} else {
@@ -213,9 +275,11 @@ export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes {
275
const unblockedLanes = pendingLanes & ~suspendedLanes;
276
if (unblockedLanes !== NoLanes) {
277
nextLanes = getHighestPriorityLanes(unblockedLanes);
278
+ nextLanePriority = return_highestLanePriority;
279
} else {
280
if (pingedLanes !== NoLanes) {
281
nextLanes = getHighestPriorityLanes(pingedLanes);
282
+ nextLanePriority = return_highestLanePriority;
283
}
284
}
285
}
@@ -249,6 +313,8 @@ export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes {
313
) {
314
// Keep working on the existing in-progress tree. Do not interrupt.
315
return wipLanes;
316
+ } else {
317
+ return_highestLanePriority = nextLanePriority;
318
}
319
}
320
@@ -443,6 +509,9 @@ export function getLanesToRetrySynchronouslyOnError(root: FiberRoot): Lanes {
509
return NoLanes;
510
}
511
512
+export function returnNextLanesPriority() {
513
+ return return_highestLanePriority;
514
+}
515
export function includesNonIdleWork(lanes: Lanes) {
516
return (lanes & NonIdleLanes) !== NoLanes;
517
}
@@ -548,6 +617,13 @@ export function higherPriorityLane(a: Lane, b: Lane) {
617
return a !== NoLane && a < b ? a : b;
618
}
619
620
+export function higherLanePriority(
621
+ a: LanePriority,
622
+ b: LanePriority,
623
+): LanePriority {
624
+ return a !== NoLanePriority && a > b ? a : b;
625
+}
626
+
627
export function createLaneMap<T>(initial: T): LaneMap<T> {
628
// Intentionally pushing one by one.
629
// https://v8.dev/blog/elements-kinds#avoid-creating-holes
packages/react-reconciler/src/ReactFiberLane.old.js
+76
@@ -11,6 +11,25 @@ import type {FiberRoot} from './ReactInternalTypes';
11
12
// TODO: Ideally these types would be opaque but that doesn't work well with
13
// our reconciler fork infra, since these leak into non-reconciler packages.
14
+export type LanePriority =
15
+ | 0
16
+ | 1
17
+ | 2
18
+ | 3
19
+ | 4
20
+ | 5
21
+ | 6
22
+ | 7
23
+ | 8
24
+ | 9
25
+ | 10
26
+ | 11
27
+ | 12
28
+ | 13
29
+ | 14
30
+ | 15
31
+ | 16
32
+ | 17;
33
34
export type Lanes = number;
35
export type Lane = number;
@@ -24,6 +43,28 @@ import {
43
} from 'shared/ReactFeatureFlags';
44
import {isDevToolsPresent} from './ReactFiberDevToolsHook.old';
45
46
+export const SyncLanePriority: LanePriority = 12;
47
+
48
+const InputContinuousHydrationLanePriority: LanePriority = 11;
49
+export const InputContinuousLanePriority: LanePriority = 10;
50
+
51
+const DefaultHydrationLanePriority: LanePriority = 9;
52
+export const DefaultLanePriority: LanePriority = 8;
53
+
54
+const TransitionHydrationPriority: LanePriority = 7;
55
+export const TransitionPriority: LanePriority = 6;
56
+
57
+const RetryLanePriority: LanePriority = 5;
58
+
59
+const SelectiveHydrationLanePriority: LanePriority = 4;
60
+
61
+const IdleHydrationLanePriority: LanePriority = 3;
62
+export const IdleLanePriority: LanePriority = 2;
63
+
64
+const OffscreenLanePriority: LanePriority = 1;
65
+
66
+export const NoLanePriority: LanePriority = 0;
67
+
68
// Lane values below should be kept in sync with getLabelsForLanes(), used by react-devtools-scheduling-profiler.
69
// If those values are changed that package should be rebuilt and redeployed.
70
@@ -127,19 +168,29 @@ export const NoTimestamp = -1;
168
let nextTransitionLane: Lane = TransitionLane1;
169
let nextRetryLane: Lane = RetryLane1;
170
171
+// "Registers" used to "return" multiple values
172
+// Used by getHighestPriorityLanes and getNextLanes:
173
+let return_highestLanePriority: LanePriority = DefaultLanePriority;
174
+
175
function getHighestPriorityLanes(lanes: Lanes | Lane): Lanes {
176
switch (getHighestPriorityLane(lanes)) {
177
case SyncLane:
178
+ return_highestLanePriority = SyncLanePriority;
179
return SyncLane;
180
case InputContinuousHydrationLane:
181
+ return_highestLanePriority = InputContinuousHydrationLanePriority;
182
return InputContinuousHydrationLane;
183
case InputContinuousLane:
184
+ return_highestLanePriority = InputContinuousLanePriority;
185
return InputContinuousLane;
186
case DefaultHydrationLane:
187
+ return_highestLanePriority = DefaultHydrationLanePriority;
188
return DefaultHydrationLane;
189
case DefaultLane:
190
+ return_highestLanePriority = DefaultLanePriority;
191
return DefaultLane;
192
case TransitionHydrationLane:
193
+ return_highestLanePriority = TransitionHydrationPriority;
194
return TransitionHydrationLane;
195
case TransitionLane1:
196
case TransitionLane2:
@@ -157,20 +208,26 @@ function getHighestPriorityLanes(lanes: Lanes | Lane): Lanes {
208
case TransitionLane14:
209
case TransitionLane15:
210
case TransitionLane16:
211
+ return_highestLanePriority = TransitionPriority;
212
return lanes & TransitionLanes;
213
case RetryLane1:
214
case RetryLane2:
215
case RetryLane3:
216
case RetryLane4:
217
case RetryLane5:
218
+ return_highestLanePriority = RetryLanePriority;
219
return lanes & RetryLanes;
220
case SelectiveHydrationLane:
221
+ return_highestLanePriority = SelectiveHydrationLanePriority;
222
return SelectiveHydrationLane;
223
case IdleHydrationLane:
224
+ return_highestLanePriority = IdleHydrationLanePriority;
225
return IdleHydrationLane;
226
case IdleLane:
227
+ return_highestLanePriority = IdleLanePriority;
228
return IdleLane;
229
case OffscreenLane:
230
+ return_highestLanePriority = OffscreenLanePriority;
231
return OffscreenLane;
232
default:
233
if (__DEV__) {
@@ -179,6 +236,7 @@ function getHighestPriorityLanes(lanes: Lanes | Lane): Lanes {
236
);
237
}
238
// This shouldn't be reachable, but as a fallback, return the entire bitmask.
239
+ return_highestLanePriority = DefaultLanePriority;
240
return lanes;
241
}
242
}
@@ -187,10 +245,12 @@ export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes {
245
// Early bailout if there's no pending work left.
246
const pendingLanes = root.pendingLanes;
247
if (pendingLanes === NoLanes) {
248
+ return_highestLanePriority = NoLanePriority;
249
return NoLanes;
250
}
251
252
let nextLanes = NoLanes;
253
+ let nextLanePriority = NoLanePriority;
254
255
const suspendedLanes = root.suspendedLanes;
256
const pingedLanes = root.pingedLanes;
@@ -202,10 +262,12 @@ export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes {
262
const nonIdleUnblockedLanes = nonIdlePendingLanes & ~suspendedLanes;
263
if (nonIdleUnblockedLanes !== NoLanes) {
264
nextLanes = getHighestPriorityLanes(nonIdleUnblockedLanes);
265
+ nextLanePriority = return_highestLanePriority;
266
} else {
267
const nonIdlePingedLanes = nonIdlePendingLanes & pingedLanes;
268
if (nonIdlePingedLanes !== NoLanes) {
269
nextLanes = getHighestPriorityLanes(nonIdlePingedLanes);
270
+ nextLanePriority = return_highestLanePriority;
271
}
272
}
273
} else {
@@ -213,9 +275,11 @@ export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes {
275
const unblockedLanes = pendingLanes & ~suspendedLanes;
276
if (unblockedLanes !== NoLanes) {
277
nextLanes = getHighestPriorityLanes(unblockedLanes);
278
+ nextLanePriority = return_highestLanePriority;
279
} else {
280
if (pingedLanes !== NoLanes) {
281
nextLanes = getHighestPriorityLanes(pingedLanes);
282
+ nextLanePriority = return_highestLanePriority;
283
}
284
}
285
}
@@ -249,6 +313,8 @@ export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes {
313
) {
314
// Keep working on the existing in-progress tree. Do not interrupt.
315
return wipLanes;
316
+ } else {
317
+ return_highestLanePriority = nextLanePriority;
318
}
319
}
320
@@ -443,6 +509,9 @@ export function getLanesToRetrySynchronouslyOnError(root: FiberRoot): Lanes {
509
return NoLanes;
510
}
511
512
+export function returnNextLanesPriority() {
513
+ return return_highestLanePriority;
514
+}
515
export function includesNonIdleWork(lanes: Lanes) {
516
return (lanes & NonIdleLanes) !== NoLanes;
517
}
@@ -548,6 +617,13 @@ export function higherPriorityLane(a: Lane, b: Lane) {
617
return a !== NoLane && a < b ? a : b;
618
}
619
620
+export function higherLanePriority(
621
+ a: LanePriority,
622
+ b: LanePriority,
623
+): LanePriority {
624
+ return a !== NoLanePriority && a > b ? a : b;
625
+}
626
+
627
export function createLaneMap<T>(initial: T): LaneMap<T> {
628
// Intentionally pushing one by one.
629
// https://v8.dev/blog/elements-kinds#avoid-creating-holes