Skip to content

Commit fa868d6

Browse files
authored
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.
1 parent eb58c39 commit fa868d6

11 files changed

+40
-60
lines changed

packages/react-dom/src/events/ReactDOMEventListener.js

+17-25
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@
88
*/
99

1010
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';
1512
import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig';
1613
import type {DOMEventName} from '../events/DOMEventNames';
17-
import type {LanePriority} from 'react-reconciler/src/ReactFiberLane.new';
1814

1915
import {
2016
isReplayableDiscreteEvent,
@@ -74,6 +70,8 @@ import {
7470
IdleEventPriority,
7571
} from 'react-reconciler/src/ReactEventPriorities';
7672

73+
// TODO: These should use the opaque EventPriority type instead of LanePriority.
74+
// Then internally we can use a Lane.
7775
const InputContinuousLanePriority = enableNewReconciler
7876
? InputContinuousLanePriority_new
7977
: InputContinuousLanePriority_old;
@@ -87,25 +85,6 @@ const getCurrentPriorityLevel = enableNewReconciler
8785
? getCurrentPriorityLevel_new
8886
: getCurrentPriorityLevel_old;
8987

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-
10988
// TODO: can we stop exporting these?
11089
export let _enabled = true;
11190

@@ -431,7 +410,20 @@ export function getEventPriority(domEventName: DOMEventName): * {
431410
// Eventually this mechanism will be replaced by a check
432411
// of the current priority on the native scheduler.
433412
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+
}
435427
}
436428
default:
437429
return DefaultEventPriority;

packages/react-noop-renderer/src/createReactNoop.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import * as Scheduler from 'scheduler/unstable_mock';
2323
import {REACT_FRAGMENT_TYPE, REACT_ELEMENT_TYPE} from 'shared/ReactSymbols';
2424
import {
2525
DefaultEventPriority,
26+
IdleEventPriority,
2627
ConcurrentRoot,
2728
LegacyRoot,
2829
} from 'react-reconciler/constants';
@@ -909,7 +910,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
909910

910911
idleUpdates<T>(fn: () => T): T {
911912
const prevEventPriority = currentEventPriority;
912-
currentEventPriority = NoopRenderer.IdleEventPriority;
913+
currentEventPriority = IdleEventPriority;
913914
try {
914915
fn();
915916
} finally {

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
*/
99

1010
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,
1515
} from './ReactFiberLane.new';

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
*/
99

1010
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,
1515
} from './ReactFiberLane.old';

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export const SelectiveHydrationLane: Lane = /* */ 0b0001000000000000000
118118
const NonIdleLanes = /* */ 0b0001111111111111111111111111111;
119119

120120
export const IdleHydrationLane: Lane = /* */ 0b0010000000000000000000000000000;
121-
const IdleLane: Lanes = /* */ 0b0100000000000000000000000000000;
121+
export const IdleLane: Lanes = /* */ 0b0100000000000000000000000000000;
122122

123123
export const OffscreenLane: Lane = /* */ 0b1000000000000000000000000000000;
124124

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export const SelectiveHydrationLane: Lane = /* */ 0b0001000000000000000
118118
const NonIdleLanes = /* */ 0b0001111111111111111111111111111;
119119

120120
export const IdleHydrationLane: Lane = /* */ 0b0010000000000000000000000000000;
121-
const IdleLane: Lanes = /* */ 0b0100000000000000000000000000000;
121+
export const IdleLane: Lanes = /* */ 0b0100000000000000000000000000000;
122122

123123
export const OffscreenLane: Lane = /* */ 0b1000000000000000000000000000000;
124124

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

-10
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,6 @@ import {
9393
} from './ReactFiberHotReloading.new';
9494
import {markRenderScheduled} from './SchedulingProfiler';
9595

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-
10696
export {registerMutableSourceForHydration} from './ReactMutableSource.new';
10797
export {createPortal} from './ReactPortal';
10898
export {

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

-10
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,6 @@ import {
9393
} from './ReactFiberHotReloading.old';
9494
import {markRenderScheduled} from './SchedulingProfiler';
9595

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-
10696
export {registerMutableSourceForHydration} from './ReactMutableSource.old';
10797
export {createPortal} from './ReactPortal';
10898
export {

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,11 @@ export function requestUpdateLane(fiber: Fiber): Lane {
436436

437437
// This update originated outside React. Ask the host environement for an
438438
// 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;
441444
}
442445

443446
function requestRetryLane(fiber: Fiber) {

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,11 @@ export function requestUpdateLane(fiber: Fiber): Lane {
436436

437437
// This update originated outside React. Ask the host environement for an
438438
// 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;
441444
}
442445

443446
function requestRetryLane(fiber: Fiber) {

packages/react-reconciler/src/ReactReconcilerConstants.js

+1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ export {
1414
DiscreteEventPriority,
1515
ContinuousEventPriority,
1616
DefaultEventPriority,
17+
IdleEventPriority,
1718
} from './ReactEventPriorities';
1819
export {ConcurrentRoot, LegacyRoot} from './ReactRootTags';

0 commit comments

Comments
 (0)