Make opaque EventPriority type a Lane internally (#21065)
Instead of LanePriority, we can use a Lane and skip the extra conversion. Eventually I want to get rid of LanePriority completely.
Andrew Clark committed
Mar 24, 2021 at 11:55 UTC
fa868d6be7d7c387887cb4f7c391fbe2d4f987ea
11 files changed
+40
-60
packages/react-dom/src/events/ReactDOMEventListener.js
+17
-25
@@ -8,13 +8,9 @@
8
*/
9
10
import type {AnyNativeEvent} from '../events/PluginModuleType';
11
-import type {
12
- FiberRoot,
13
- ReactPriorityLevel,
14
-} from 'react-reconciler/src/ReactInternalTypes';
11
+import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
12
import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig';
13
import type {DOMEventName} from '../events/DOMEventNames';
17
-import type {LanePriority} from 'react-reconciler/src/ReactFiberLane.new';
14
15
import {
16
isReplayableDiscreteEvent,
@@ -74,6 +70,8 @@ import {
70
IdleEventPriority,
71
} from 'react-reconciler/src/ReactEventPriorities';
72
73
+// TODO: These should use the opaque EventPriority type instead of LanePriority.
74
+// Then internally we can use a Lane.
75
const InputContinuousLanePriority = enableNewReconciler
76
? InputContinuousLanePriority_new
77
: InputContinuousLanePriority_old;
@@ -87,25 +85,6 @@ const getCurrentPriorityLevel = enableNewReconciler
85
? getCurrentPriorityLevel_new
86
: getCurrentPriorityLevel_old;
87
90
-function schedulerPriorityToLanePriority(
91
- schedulerPriorityLevel: ReactPriorityLevel,
92
-): LanePriority {
93
- switch (schedulerPriorityLevel) {
94
- case ImmediateSchedulerPriority:
95
- return DiscreteEventPriority;
96
- case UserBlockingSchedulerPriority:
97
- return ContinuousEventPriority;
98
- case NormalSchedulerPriority:
99
- case LowSchedulerPriority:
100
- // TODO: Handle LowSchedulerPriority, somehow. Maybe the same lane as hydration.
101
- return DefaultEventPriority;
102
- case IdleSchedulerPriority:
103
- return IdleEventPriority;
104
- default:
105
- return DefaultEventPriority;
106
- }
107
-}
108
-
88
// TODO: can we stop exporting these?
89
export let _enabled = true;
90
@@ -431,7 +410,20 @@ export function getEventPriority(domEventName: DOMEventName): * {
410
// Eventually this mechanism will be replaced by a check
411
// of the current priority on the native scheduler.
412
const schedulerPriority = getCurrentPriorityLevel();
434
- return schedulerPriorityToLanePriority(schedulerPriority);
413
+ switch (schedulerPriority) {
414
+ case ImmediateSchedulerPriority:
415
+ return DiscreteEventPriority;
416
+ case UserBlockingSchedulerPriority:
417
+ return ContinuousEventPriority;
418
+ case NormalSchedulerPriority:
419
+ case LowSchedulerPriority:
420
+ // TODO: Handle LowSchedulerPriority, somehow. Maybe the same lane as hydration.
421
+ return DefaultEventPriority;
422
+ case IdleSchedulerPriority:
423
+ return IdleEventPriority;
424
+ default:
425
+ return DefaultEventPriority;
426
+ }
427
}
428
default:
429
return DefaultEventPriority;
packages/react-noop-renderer/src/createReactNoop.js
+2
-1
@@ -23,6 +23,7 @@ import * as Scheduler from 'scheduler/unstable_mock';
23
import {REACT_FRAGMENT_TYPE, REACT_ELEMENT_TYPE} from 'shared/ReactSymbols';
24
import {
25
DefaultEventPriority,
26
+ IdleEventPriority,
27
ConcurrentRoot,
28
LegacyRoot,
29
} from 'react-reconciler/constants';
@@ -909,7 +910,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
910
911
idleUpdates<T>(fn: () => T): T {
912
const prevEventPriority = currentEventPriority;
912
- currentEventPriority = NoopRenderer.IdleEventPriority;
913
+ currentEventPriority = IdleEventPriority;
914
try {
915
fn();
916
} finally {
packages/react-reconciler/src/ReactEventPriorities.new.js
+4
-4
@@ -8,8 +8,8 @@
8
*/
9
10
export {
11
- SyncLanePriority as DiscreteEventPriority,
12
- InputContinuousLanePriority as ContinuousEventPriority,
13
- DefaultLanePriority as DefaultEventPriority,
14
- IdleLanePriority as IdleEventPriority,
11
+ SyncLane as DiscreteEventPriority,
12
+ InputContinuousLane as ContinuousEventPriority,
13
+ DefaultLane as DefaultEventPriority,
14
+ IdleLane as IdleEventPriority,
15
} from './ReactFiberLane.new';
packages/react-reconciler/src/ReactEventPriorities.old.js
+4
-4
@@ -8,8 +8,8 @@
8
*/
9
10
export {
11
- SyncLanePriority as DiscreteEventPriority,
12
- InputContinuousLanePriority as ContinuousEventPriority,
13
- DefaultLanePriority as DefaultEventPriority,
14
- IdleLanePriority as IdleEventPriority,
11
+ SyncLane as DiscreteEventPriority,
12
+ InputContinuousLane as ContinuousEventPriority,
13
+ DefaultLane as DefaultEventPriority,
14
+ IdleLane as IdleEventPriority,
15
} from './ReactFiberLane.old';
packages/react-reconciler/src/ReactFiberLane.new.js
+1
-1
@@ -118,7 +118,7 @@ export const SelectiveHydrationLane: Lane = /* */ 0b0001000000000000000
118
const NonIdleLanes = /* */ 0b0001111111111111111111111111111;
119
120
export const IdleHydrationLane: Lane = /* */ 0b0010000000000000000000000000000;
121
-const IdleLane: Lanes = /* */ 0b0100000000000000000000000000000;
121
+export const IdleLane: Lanes = /* */ 0b0100000000000000000000000000000;
122
123
export const OffscreenLane: Lane = /* */ 0b1000000000000000000000000000000;
124
packages/react-reconciler/src/ReactFiberLane.old.js
+1
-1
@@ -118,7 +118,7 @@ export const SelectiveHydrationLane: Lane = /* */ 0b0001000000000000000
118
const NonIdleLanes = /* */ 0b0001111111111111111111111111111;
119
120
export const IdleHydrationLane: Lane = /* */ 0b0010000000000000000000000000000;
121
-const IdleLane: Lanes = /* */ 0b0100000000000000000000000000000;
121
+export const IdleLane: Lanes = /* */ 0b0100000000000000000000000000000;
122
123
export const OffscreenLane: Lane = /* */ 0b1000000000000000000000000000000;
124
packages/react-reconciler/src/ReactFiberReconciler.new.js
-10
@@ -93,16 +93,6 @@ import {
93
} from './ReactFiberHotReloading.new';
94
import {markRenderScheduled} from './SchedulingProfiler';
95
96
-// Ideally host configs would import these constants from the reconciler
97
-// entry point, but we can't do this because of a circular dependency.
98
-// They are used by third-party renderers so they need to stay up to date.
99
-export {
100
- SyncLanePriority as DiscreteEventPriority,
101
- InputContinuousLanePriority as ContinuousEventPriority,
102
- DefaultLanePriority as DefaultEventPriority,
103
- IdleLanePriority as IdleEventPriority,
104
-} from './ReactFiberLane.new';
105
-
96
export {registerMutableSourceForHydration} from './ReactMutableSource.new';
97
export {createPortal} from './ReactPortal';
98
export {
packages/react-reconciler/src/ReactFiberReconciler.old.js
-10
@@ -93,16 +93,6 @@ import {
93
} from './ReactFiberHotReloading.old';
94
import {markRenderScheduled} from './SchedulingProfiler';
95
96
-// Ideally host configs would import these constants from the reconciler
97
-// entry point, but we can't do this because of a circular dependency.
98
-// They are used by third-party renderers so they need to stay up to date.
99
-export {
100
- SyncLanePriority as DiscreteEventPriority,
101
- InputContinuousLanePriority as ContinuousEventPriority,
102
- DefaultLanePriority as DefaultEventPriority,
103
- IdleLanePriority as IdleEventPriority,
104
-} from './ReactFiberLane.old';
105
-
96
export {registerMutableSourceForHydration} from './ReactMutableSource.old';
97
export {createPortal} from './ReactPortal';
98
export {
packages/react-reconciler/src/ReactFiberWorkLoop.new.js
+5
-2
@@ -436,8 +436,11 @@ export function requestUpdateLane(fiber: Fiber): Lane {
436
437
// This update originated outside React. Ask the host environement for an
438
// appropriate priority, based on the type of event.
439
- const eventLanePriority = getCurrentEventPriority();
440
- return findUpdateLane(eventLanePriority);
439
+ //
440
+ // The opaque type returned by the host config is internally a lane, so we can
441
+ // use that directly.
442
+ const eventLane = getCurrentEventPriority();
443
+ return eventLane;
444
}
445
446
function requestRetryLane(fiber: Fiber) {
packages/react-reconciler/src/ReactFiberWorkLoop.old.js
+5
-2
@@ -436,8 +436,11 @@ export function requestUpdateLane(fiber: Fiber): Lane {
436
437
// This update originated outside React. Ask the host environement for an
438
// appropriate priority, based on the type of event.
439
- const eventLanePriority = getCurrentEventPriority();
440
- return findUpdateLane(eventLanePriority);
439
+ //
440
+ // The opaque type returned by the host config is internally a lane, so we can
441
+ // use that directly.
442
+ const eventLane = getCurrentEventPriority();
443
+ return eventLane;
444
}
445
446
function requestRetryLane(fiber: Fiber) {
packages/react-reconciler/src/ReactReconcilerConstants.js
+1
@@ -14,5 +14,6 @@ export {
14
DiscreteEventPriority,
15
ContinuousEventPriority,
16
DefaultEventPriority,
17
+ IdleEventPriority,
18
} from './ReactEventPriorities';
19
export {ConcurrentRoot, LegacyRoot} from './ReactRootTags';