Skip to content

Commit 0a39796

Browse files
rickhanloniikoto
authored andcommitted
Land enableNativeEventPriorityInference (facebook#20955)
* Land enableNativeEventPriorityInference * Move schedulerPriorityToLanePriority * Remove obsolete comment
1 parent 259f4ff commit 0a39796

19 files changed

+45
-208
lines changed

packages/react-dom/src/__tests__/ReactDOMNativeEventHeuristic-test.js

-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
4343
}
4444

4545
// @gate experimental
46-
// @gate enableNativeEventPriorityInference
4746
it('ignores discrete events on a pending removed element', async () => {
4847
const disableButtonRef = React.createRef();
4948
const submitButtonRef = React.createRef();
@@ -95,7 +94,6 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
9594
});
9695

9796
// @gate experimental
98-
// @gate enableNativeEventPriorityInference
9997
it('ignores discrete events on a pending removed event listener', async () => {
10098
const disableButtonRef = React.createRef();
10199
const submitButtonRef = React.createRef();
@@ -165,7 +163,6 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
165163
});
166164

167165
// @gate experimental
168-
// @gate enableNativeEventPriorityInference
169166
it('uses the newest discrete events on a pending changed event listener', async () => {
170167
const enableButtonRef = React.createRef();
171168
const submitButtonRef = React.createRef();
@@ -229,7 +226,6 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
229226
});
230227

231228
// @gate experimental
232-
// @gate enableNativeEventPriorityInference
233229
it('mouse over should be user-blocking but not discrete', async () => {
234230
const root = ReactDOM.unstable_createRoot(container);
235231

@@ -260,7 +256,6 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
260256
});
261257

262258
// @gate experimental
263-
// @gate enableNativeEventPriorityInference
264259
it('mouse enter should be user-blocking but not discrete', async () => {
265260
const root = ReactDOM.unstable_createRoot(container);
266261

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

+35-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
*/
99

1010
import type {AnyNativeEvent} from '../events/PluginModuleType';
11-
import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
11+
import type {
12+
FiberRoot,
13+
ReactPriorityLevel,
14+
} from 'react-reconciler/src/ReactInternalTypes';
1215
import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig';
1316
import type {DOMEventName} from '../events/DOMEventNames';
1417

@@ -50,18 +53,27 @@ import {
5053
DefaultLanePriority as DefaultLanePriority_old,
5154
getCurrentUpdateLanePriority as getCurrentUpdateLanePriority_old,
5255
setCurrentUpdateLanePriority as setCurrentUpdateLanePriority_old,
53-
schedulerPriorityToLanePriority as schedulerPriorityToLanePriority_old,
5456
} from 'react-reconciler/src/ReactFiberLane.old';
5557
import {
5658
InputDiscreteLanePriority as InputDiscreteLanePriority_new,
5759
InputContinuousLanePriority as InputContinuousLanePriority_new,
5860
DefaultLanePriority as DefaultLanePriority_new,
5961
getCurrentUpdateLanePriority as getCurrentUpdateLanePriority_new,
6062
setCurrentUpdateLanePriority as setCurrentUpdateLanePriority_new,
61-
schedulerPriorityToLanePriority as schedulerPriorityToLanePriority_new,
63+
SyncLanePriority,
64+
IdleLanePriority,
65+
NoLanePriority,
6266
} from 'react-reconciler/src/ReactFiberLane.new';
6367
import {getCurrentPriorityLevel as getCurrentPriorityLevel_old} from 'react-reconciler/src/SchedulerWithReactIntegration.old';
64-
import {getCurrentPriorityLevel as getCurrentPriorityLevel_new} from 'react-reconciler/src/SchedulerWithReactIntegration.new';
68+
import {
69+
getCurrentPriorityLevel as getCurrentPriorityLevel_new,
70+
IdlePriority as IdleSchedulerPriority,
71+
ImmediatePriority as ImmediateSchedulerPriority,
72+
LowPriority as LowSchedulerPriority,
73+
NormalPriority as NormalSchedulerPriority,
74+
UserBlockingPriority as UserBlockingSchedulerPriority,
75+
} from 'react-reconciler/src/SchedulerWithReactIntegration.new';
76+
import type {LanePriority} from 'react-reconciler/src/ReactFiberLane.new';
6577

6678
const InputDiscreteLanePriority = enableNewReconciler
6779
? InputDiscreteLanePriority_new
@@ -78,13 +90,29 @@ const getCurrentUpdateLanePriority = enableNewReconciler
7890
const setCurrentUpdateLanePriority = enableNewReconciler
7991
? setCurrentUpdateLanePriority_new
8092
: setCurrentUpdateLanePriority_old;
81-
const schedulerPriorityToLanePriority = enableNewReconciler
82-
? schedulerPriorityToLanePriority_new
83-
: schedulerPriorityToLanePriority_old;
8493
const getCurrentPriorityLevel = enableNewReconciler
8594
? getCurrentPriorityLevel_new
8695
: getCurrentPriorityLevel_old;
8796

97+
function schedulerPriorityToLanePriority(
98+
schedulerPriorityLevel: ReactPriorityLevel,
99+
): LanePriority {
100+
switch (schedulerPriorityLevel) {
101+
case ImmediateSchedulerPriority:
102+
return SyncLanePriority;
103+
case UserBlockingSchedulerPriority:
104+
return InputContinuousLanePriority;
105+
case NormalSchedulerPriority:
106+
case LowSchedulerPriority:
107+
// TODO: Handle LowSchedulerPriority, somehow. Maybe the same lane as hydration.
108+
return DefaultLanePriority;
109+
case IdleSchedulerPriority:
110+
return IdleLanePriority;
111+
default:
112+
return NoLanePriority;
113+
}
114+
}
115+
88116
// TODO: can we stop exporting these?
89117
export let _enabled = true;
90118

@@ -410,8 +438,6 @@ export function getEventPriority(domEventName: DOMEventName): * {
410438
// Eventually this mechanism will be replaced by a check
411439
// of the current priority on the native scheduler.
412440
const schedulerPriority = getCurrentPriorityLevel();
413-
// TODO: Inline schedulerPriorityToLanePriority into this file
414-
// when we delete the enableNativeEventPriorityInference flag.
415441
return schedulerPriorityToLanePriority(schedulerPriority);
416442
}
417443
default:

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

+6-14
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import {
2727
LegacyRoot,
2828
} from 'react-reconciler/src/ReactRootTags';
2929

30-
import {enableNativeEventPriorityInference} from 'shared/ReactFeatureFlags';
3130
import ReactSharedInternals from 'shared/ReactSharedInternals';
3231
import enqueueTask from 'shared/enqueueTask';
3332
const {IsSomeRendererActing} = ReactSharedInternals;
@@ -934,19 +933,12 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
934933
discreteUpdates: NoopRenderer.discreteUpdates,
935934

936935
idleUpdates<T>(fn: () => T): T {
937-
if (enableNativeEventPriorityInference) {
938-
const prevEventPriority = currentEventPriority;
939-
currentEventPriority = NoopRenderer.IdleEventPriority;
940-
try {
941-
fn();
942-
} finally {
943-
currentEventPriority = prevEventPriority;
944-
}
945-
} else {
946-
return Scheduler.unstable_runWithPriority(
947-
Scheduler.unstable_IdlePriority,
948-
fn,
949-
);
936+
const prevEventPriority = currentEventPriority;
937+
currentEventPriority = NoopRenderer.IdleEventPriority;
938+
try {
939+
fn();
940+
} finally {
941+
currentEventPriority = prevEventPriority;
950942
}
951943
},
952944

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

-20
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import {
4242
ImmediatePriority as ImmediateSchedulerPriority,
4343
UserBlockingPriority as UserBlockingSchedulerPriority,
4444
NormalPriority as NormalSchedulerPriority,
45-
LowPriority as LowSchedulerPriority,
4645
IdlePriority as IdleSchedulerPriority,
4746
NoPriority as NoSchedulerPriority,
4847
} from './SchedulerWithReactIntegration.new';
@@ -275,25 +274,6 @@ function getHighestPriorityLanes(lanes: Lanes | Lane): Lanes {
275274
}
276275
}
277276

278-
export function schedulerPriorityToLanePriority(
279-
schedulerPriorityLevel: ReactPriorityLevel,
280-
): LanePriority {
281-
switch (schedulerPriorityLevel) {
282-
case ImmediateSchedulerPriority:
283-
return SyncLanePriority;
284-
case UserBlockingSchedulerPriority:
285-
return InputContinuousLanePriority;
286-
case NormalSchedulerPriority:
287-
case LowSchedulerPriority:
288-
// TODO: Handle LowSchedulerPriority, somehow. Maybe the same lane as hydration.
289-
return DefaultLanePriority;
290-
case IdleSchedulerPriority:
291-
return IdleLanePriority;
292-
default:
293-
return NoLanePriority;
294-
}
295-
}
296-
297277
export function lanePriorityToSchedulerPriority(
298278
lanePriority: LanePriority,
299279
): ReactPriorityLevel {

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

-20
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import {
4242
ImmediatePriority as ImmediateSchedulerPriority,
4343
UserBlockingPriority as UserBlockingSchedulerPriority,
4444
NormalPriority as NormalSchedulerPriority,
45-
LowPriority as LowSchedulerPriority,
4645
IdlePriority as IdleSchedulerPriority,
4746
NoPriority as NoSchedulerPriority,
4847
} from './SchedulerWithReactIntegration.old';
@@ -275,25 +274,6 @@ function getHighestPriorityLanes(lanes: Lanes | Lane): Lanes {
275274
}
276275
}
277276

278-
export function schedulerPriorityToLanePriority(
279-
schedulerPriorityLevel: ReactPriorityLevel,
280-
): LanePriority {
281-
switch (schedulerPriorityLevel) {
282-
case ImmediateSchedulerPriority:
283-
return SyncLanePriority;
284-
case UserBlockingSchedulerPriority:
285-
return InputContinuousLanePriority;
286-
case NormalSchedulerPriority:
287-
case LowSchedulerPriority:
288-
// TODO: Handle LowSchedulerPriority, somehow. Maybe the same lane as hydration.
289-
return DefaultLanePriority;
290-
case IdleSchedulerPriority:
291-
return IdleLanePriority;
292-
default:
293-
return NoLanePriority;
294-
}
295-
}
296-
297277
export function lanePriorityToSchedulerPriority(
298278
lanePriority: LanePriority,
299279
): ReactPriorityLevel {

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

+2-11
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import {
3232
disableSchedulerTimeoutInWorkLoop,
3333
enableStrictEffects,
3434
skipUnmountedBoundaries,
35-
enableNativeEventPriorityInference,
3635
} from 'shared/ReactFeatureFlags';
3736
import ReactSharedInternals from 'shared/ReactSharedInternals';
3837
import invariant from 'shared/invariant';
@@ -168,7 +167,6 @@ import {
168167
markRootExpired,
169168
markDiscreteUpdatesExpired,
170169
markRootFinished,
171-
schedulerPriorityToLanePriority,
172170
lanePriorityToSchedulerPriority,
173171
higherLanePriority,
174172
} from './ReactFiberLane.new';
@@ -456,15 +454,8 @@ export function requestUpdateLane(fiber: Fiber): Lane {
456454
const currentLanePriority = getCurrentUpdateLanePriority();
457455
lane = findUpdateLane(currentLanePriority);
458456
} else {
459-
if (enableNativeEventPriorityInference) {
460-
const eventLanePriority = getCurrentEventPriority();
461-
lane = findUpdateLane(eventLanePriority);
462-
} else {
463-
const schedulerLanePriority = schedulerPriorityToLanePriority(
464-
schedulerPriority,
465-
);
466-
lane = findUpdateLane(schedulerLanePriority);
467-
}
457+
const eventLanePriority = getCurrentEventPriority();
458+
lane = findUpdateLane(eventLanePriority);
468459
}
469460

470461
return lane;

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

+2-11
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import {
3232
disableSchedulerTimeoutInWorkLoop,
3333
enableStrictEffects,
3434
skipUnmountedBoundaries,
35-
enableNativeEventPriorityInference,
3635
} from 'shared/ReactFeatureFlags';
3736
import ReactSharedInternals from 'shared/ReactSharedInternals';
3837
import invariant from 'shared/invariant';
@@ -168,7 +167,6 @@ import {
168167
markRootExpired,
169168
markDiscreteUpdatesExpired,
170169
markRootFinished,
171-
schedulerPriorityToLanePriority,
172170
lanePriorityToSchedulerPriority,
173171
higherLanePriority,
174172
} from './ReactFiberLane.old';
@@ -456,15 +454,8 @@ export function requestUpdateLane(fiber: Fiber): Lane {
456454
const currentLanePriority = getCurrentUpdateLanePriority();
457455
lane = findUpdateLane(currentLanePriority);
458456
} else {
459-
if (enableNativeEventPriorityInference) {
460-
const eventLanePriority = getCurrentEventPriority();
461-
lane = findUpdateLane(eventLanePriority);
462-
} else {
463-
const schedulerLanePriority = schedulerPriorityToLanePriority(
464-
schedulerPriority,
465-
);
466-
lane = findUpdateLane(schedulerLanePriority);
467-
}
457+
const eventLanePriority = getCurrentEventPriority();
458+
lane = findUpdateLane(eventLanePriority);
468459
}
469460

470461
return lane;

0 commit comments

Comments
 (0)