Land enableNativeEventPriorityInference (#20955)
* Land enableNativeEventPriorityInference * Move schedulerPriorityToLanePriority * Remove obsolete comment
Ricky committed
Mar 9, 2021 at 23:59 UTC
e4d4b7074d89a9a94f352ef9336ba0fdc620d8b4
19 files changed
+45
-208
packages/react-dom/src/__tests__/ReactDOMNativeEventHeuristic-test.js
-5
@@ -43,7 +43,6 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
43
}
44
45
// @gate experimental
46
- // @gate enableNativeEventPriorityInference
46
it('ignores discrete events on a pending removed element', async () => {
47
const disableButtonRef = React.createRef();
48
const submitButtonRef = React.createRef();
@@ -95,7 +94,6 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
94
});
95
96
// @gate experimental
98
- // @gate enableNativeEventPriorityInference
97
it('ignores discrete events on a pending removed event listener', async () => {
98
const disableButtonRef = React.createRef();
99
const submitButtonRef = React.createRef();
@@ -165,7 +163,6 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
163
});
164
165
// @gate experimental
168
- // @gate enableNativeEventPriorityInference
166
it('uses the newest discrete events on a pending changed event listener', async () => {
167
const enableButtonRef = React.createRef();
168
const submitButtonRef = React.createRef();
@@ -229,7 +226,6 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
226
});
227
228
// @gate experimental
232
- // @gate enableNativeEventPriorityInference
229
it('mouse over should be user-blocking but not discrete', async () => {
230
const root = ReactDOM.unstable_createRoot(container);
231
@@ -260,7 +256,6 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
256
});
257
258
// @gate experimental
263
- // @gate enableNativeEventPriorityInference
259
it('mouse enter should be user-blocking but not discrete', async () => {
260
const root = ReactDOM.unstable_createRoot(container);
261
packages/react-dom/src/events/ReactDOMEventListener.js
+35
-9
@@ -8,7 +8,10 @@
8
*/
9
10
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';
15
import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig';
16
import type {DOMEventName} from '../events/DOMEventNames';
17
@@ -50,7 +53,6 @@ import {
53
DefaultLanePriority as DefaultLanePriority_old,
54
getCurrentUpdateLanePriority as getCurrentUpdateLanePriority_old,
55
setCurrentUpdateLanePriority as setCurrentUpdateLanePriority_old,
53
- schedulerPriorityToLanePriority as schedulerPriorityToLanePriority_old,
56
} from 'react-reconciler/src/ReactFiberLane.old';
57
import {
58
InputDiscreteLanePriority as InputDiscreteLanePriority_new,
@@ -58,10 +60,20 @@ import {
60
DefaultLanePriority as DefaultLanePriority_new,
61
getCurrentUpdateLanePriority as getCurrentUpdateLanePriority_new,
62
setCurrentUpdateLanePriority as setCurrentUpdateLanePriority_new,
61
- schedulerPriorityToLanePriority as schedulerPriorityToLanePriority_new,
63
+ SyncLanePriority,
64
+ IdleLanePriority,
65
+ NoLanePriority,
66
} from 'react-reconciler/src/ReactFiberLane.new';
67
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';
77
78
const InputDiscreteLanePriority = enableNewReconciler
79
? InputDiscreteLanePriority_new
@@ -78,13 +90,29 @@ const getCurrentUpdateLanePriority = enableNewReconciler
90
const setCurrentUpdateLanePriority = enableNewReconciler
91
? setCurrentUpdateLanePriority_new
92
: setCurrentUpdateLanePriority_old;
81
-const schedulerPriorityToLanePriority = enableNewReconciler
82
- ? schedulerPriorityToLanePriority_new
83
- : schedulerPriorityToLanePriority_old;
93
const getCurrentPriorityLevel = enableNewReconciler
94
? getCurrentPriorityLevel_new
95
: getCurrentPriorityLevel_old;
96
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
+
116
// TODO: can we stop exporting these?
117
export let _enabled = true;
118
@@ -410,8 +438,6 @@ export function getEventPriority(domEventName: DOMEventName): * {
438
// Eventually this mechanism will be replaced by a check
439
// of the current priority on the native scheduler.
440
const schedulerPriority = getCurrentPriorityLevel();
413
- // TODO: Inline schedulerPriorityToLanePriority into this file
414
- // when we delete the enableNativeEventPriorityInference flag.
441
return schedulerPriorityToLanePriority(schedulerPriority);
442
}
443
default:
packages/react-noop-renderer/src/createReactNoop.js
+6
-14
@@ -27,7 +27,6 @@ import {
27
LegacyRoot,
28
} from 'react-reconciler/src/ReactRootTags';
29
30
-import {enableNativeEventPriorityInference} from 'shared/ReactFeatureFlags';
30
import ReactSharedInternals from 'shared/ReactSharedInternals';
31
import enqueueTask from 'shared/enqueueTask';
32
const {IsSomeRendererActing} = ReactSharedInternals;
@@ -934,19 +933,12 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
933
discreteUpdates: NoopRenderer.discreteUpdates,
934
935
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;
942
}
943
},
944
packages/react-reconciler/src/ReactFiberLane.new.js
-20
@@ -42,7 +42,6 @@ import {
42
ImmediatePriority as ImmediateSchedulerPriority,
43
UserBlockingPriority as UserBlockingSchedulerPriority,
44
NormalPriority as NormalSchedulerPriority,
45
- LowPriority as LowSchedulerPriority,
45
IdlePriority as IdleSchedulerPriority,
46
NoPriority as NoSchedulerPriority,
47
} from './SchedulerWithReactIntegration.new';
@@ -275,25 +274,6 @@ function getHighestPriorityLanes(lanes: Lanes | Lane): Lanes {
274
}
275
}
276
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
-
277
export function lanePriorityToSchedulerPriority(
278
lanePriority: LanePriority,
279
): ReactPriorityLevel {
packages/react-reconciler/src/ReactFiberLane.old.js
-20
@@ -42,7 +42,6 @@ import {
42
ImmediatePriority as ImmediateSchedulerPriority,
43
UserBlockingPriority as UserBlockingSchedulerPriority,
44
NormalPriority as NormalSchedulerPriority,
45
- LowPriority as LowSchedulerPriority,
45
IdlePriority as IdleSchedulerPriority,
46
NoPriority as NoSchedulerPriority,
47
} from './SchedulerWithReactIntegration.old';
@@ -275,25 +274,6 @@ function getHighestPriorityLanes(lanes: Lanes | Lane): Lanes {
274
}
275
}
276
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
-
277
export function lanePriorityToSchedulerPriority(
278
lanePriority: LanePriority,
279
): ReactPriorityLevel {
packages/react-reconciler/src/ReactFiberWorkLoop.new.js
+2
-11
@@ -32,7 +32,6 @@ import {
32
disableSchedulerTimeoutInWorkLoop,
33
enableStrictEffects,
34
skipUnmountedBoundaries,
35
- enableNativeEventPriorityInference,
35
} from 'shared/ReactFeatureFlags';
36
import ReactSharedInternals from 'shared/ReactSharedInternals';
37
import invariant from 'shared/invariant';
@@ -168,7 +167,6 @@ import {
167
markRootExpired,
168
markDiscreteUpdatesExpired,
169
markRootFinished,
171
- schedulerPriorityToLanePriority,
170
lanePriorityToSchedulerPriority,
171
higherLanePriority,
172
} from './ReactFiberLane.new';
@@ -456,15 +454,8 @@ export function requestUpdateLane(fiber: Fiber): Lane {
454
const currentLanePriority = getCurrentUpdateLanePriority();
455
lane = findUpdateLane(currentLanePriority);
456
} 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);
459
}
460
461
return lane;
packages/react-reconciler/src/ReactFiberWorkLoop.old.js
+2
-11
@@ -32,7 +32,6 @@ import {
32
disableSchedulerTimeoutInWorkLoop,
33
enableStrictEffects,
34
skipUnmountedBoundaries,
35
- enableNativeEventPriorityInference,
35
} from 'shared/ReactFeatureFlags';
36
import ReactSharedInternals from 'shared/ReactSharedInternals';
37
import invariant from 'shared/invariant';
@@ -168,7 +167,6 @@ import {
167
markRootExpired,
168
markDiscreteUpdatesExpired,
169
markRootFinished,
171
- schedulerPriorityToLanePriority,
170
lanePriorityToSchedulerPriority,
171
higherLanePriority,
172
} from './ReactFiberLane.old';
@@ -456,15 +454,8 @@ export function requestUpdateLane(fiber: Fiber): Lane {
454
const currentLanePriority = getCurrentUpdateLanePriority();
455
lane = findUpdateLane(currentLanePriority);
456
} 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);
459
}
460
461
return lane;
packages/react-reconciler/src/__tests__/ReactSchedulerIntegration-test.js
-106
@@ -13,10 +13,7 @@
13
let React;
14
let ReactNoop;
15
let Scheduler;
16
-let ImmediatePriority;
17
-let UserBlockingPriority;
16
let NormalPriority;
19
-let LowPriority;
17
let IdlePriority;
18
let runWithPriority;
19
let startTransition;
@@ -28,33 +25,12 @@ describe('ReactSchedulerIntegration', () => {
25
React = require('react');
26
ReactNoop = require('react-noop-renderer');
27
Scheduler = require('scheduler');
31
- ImmediatePriority = Scheduler.unstable_ImmediatePriority;
32
- UserBlockingPriority = Scheduler.unstable_UserBlockingPriority;
28
NormalPriority = Scheduler.unstable_NormalPriority;
34
- LowPriority = Scheduler.unstable_LowPriority;
29
IdlePriority = Scheduler.unstable_IdlePriority;
30
runWithPriority = Scheduler.unstable_runWithPriority;
31
startTransition = React.unstable_startTransition;
32
});
33
40
- function getCurrentPriorityAsString() {
41
- const priorityLevel = Scheduler.unstable_getCurrentPriorityLevel();
42
- switch (priorityLevel) {
43
- case ImmediatePriority:
44
- return 'Immediate';
45
- case UserBlockingPriority:
46
- return 'UserBlocking';
47
- case NormalPriority:
48
- return 'Normal';
49
- case LowPriority:
50
- return 'Low';
51
- case IdlePriority:
52
- return 'Idle';
53
- default:
54
- throw Error('Unknown priority level: ' + priorityLevel);
55
- }
56
- }
57
-
34
// Note: This is based on a similar component we use in www. We can delete
35
// once the extra div wrapper is no longer necessary.
36
function LegacyHiddenDiv({children, mode}) {
@@ -68,66 +44,6 @@ describe('ReactSchedulerIntegration', () => {
44
);
45
}
46
71
- // TODO: Figure out what to do with these tests. I don't think most of them
72
- // make sense once we decouple Scheduler from React. Perhaps need similar
73
- // tests for React DOM.
74
- // @gate !enableNativeEventPriorityInference
75
- it('has correct priority during rendering', () => {
76
- function ReadPriority() {
77
- Scheduler.unstable_yieldValue(
78
- 'Priority: ' + getCurrentPriorityAsString(),
79
- );
80
- return null;
81
- }
82
- ReactNoop.render(<ReadPriority />);
83
- expect(Scheduler).toFlushAndYield(['Priority: Normal']);
84
-
85
- runWithPriority(UserBlockingPriority, () => {
86
- ReactNoop.render(<ReadPriority />);
87
- });
88
- expect(Scheduler).toFlushAndYield(['Priority: UserBlocking']);
89
-
90
- runWithPriority(IdlePriority, () => {
91
- ReactNoop.render(<ReadPriority />);
92
- });
93
- expect(Scheduler).toFlushAndYield(['Priority: Idle']);
94
- });
95
-
96
- // TODO: Figure out what to do with these tests. I don't think most of them
97
- // make sense once we decouple Scheduler from React. Perhaps need similar
98
- // tests for React DOM.
99
- // @gate !enableNativeEventPriorityInference
100
- it('has correct priority when continuing a render after yielding', () => {
101
- function ReadPriority() {
102
- Scheduler.unstable_yieldValue(
103
- 'Priority: ' + getCurrentPriorityAsString(),
104
- );
105
- return null;
106
- }
107
-
108
- runWithPriority(UserBlockingPriority, () => {
109
- ReactNoop.render(
110
- <>
111
- <ReadPriority />
112
- <ReadPriority />
113
- <ReadPriority />
114
- </>,
115
- );
116
- });
117
-
118
- // Render part of the tree
119
- expect(Scheduler).toFlushAndYieldThrough(['Priority: UserBlocking']);
120
-
121
- // Priority is set back to normal when yielding
122
- expect(getCurrentPriorityAsString()).toEqual('Normal');
123
-
124
- // Priority is restored to user-blocking when continuing
125
- expect(Scheduler).toFlushAndYield([
126
- 'Priority: UserBlocking',
127
- 'Priority: UserBlocking',
128
- ]);
129
- });
130
-
47
it('passive effects are called before Normal-pri scheduled in layout effects', async () => {
48
const {useEffect, useLayoutEffect} = React;
49
function Effects({step}) {
@@ -172,28 +88,6 @@ describe('ReactSchedulerIntegration', () => {
88
]);
89
});
90
175
- // TODO: Figure out what to do with these tests. I don't think most of them
176
- // make sense once we decouple Scheduler from React. Perhaps need similar
177
- // tests for React DOM.
178
- // @gate !enableNativeEventPriorityInference
179
- it('after completing a level of work, infers priority of the next batch based on its expiration time', () => {
180
- function App({label}) {
181
- Scheduler.unstable_yieldValue(
182
- `${label} [${getCurrentPriorityAsString()}]`,
183
- );
184
- return label;
185
- }
186
-
187
- // Schedule two separate updates at different priorities
188
- runWithPriority(UserBlockingPriority, () => {
189
- ReactNoop.render(<App label="A" />);
190
- });
191
- ReactNoop.render(<App label="B" />);
192
-
193
- // The second update should run at normal priority
194
- expect(Scheduler).toFlushAndYield(['A [UserBlocking]', 'B [Normal]']);
195
- });
196
-
91
it('requests a paint after committing', () => {
92
const scheduleCallback = Scheduler.unstable_scheduleCallback;
93
packages/react-reconciler/src/__tests__/useMutableSourceHydration-test.js
-1
@@ -341,7 +341,6 @@ describe('useMutableSourceHydration', () => {
341
});
342
343
// @gate experimental
344
- // @gate enableNativeEventPriorityInference
344
it('should detect a tear during a higher priority interruption', () => {
345
const source = createSource('one');
346
const mutableSource = createMutableSource(source, param => param.version);
packages/shared/ReactFeatureFlags.js
-2
@@ -152,6 +152,4 @@ export const disableSchedulerTimeoutInWorkLoop = false;
152
153
export const enableSyncMicroTasks = false;
154
155
-export const enableNativeEventPriorityInference = false;
156
-
155
export const enableLazyContextPropagation = false;
packages/shared/forks/ReactFeatureFlags.native-fb.js
-1
@@ -58,7 +58,6 @@ export const enableUseRefAccessWarning = false;
58
export const enableRecursiveCommitTraversal = false;
59
export const disableSchedulerTimeoutInWorkLoop = false;
60
export const enableSyncMicroTasks = false;
61
-export const enableNativeEventPriorityInference = false;
61
export const enableLazyContextPropagation = false;
62
63
// Flow magic to verify the exports of this file match the original version.
packages/shared/forks/ReactFeatureFlags.native-oss.js
-1
@@ -57,7 +57,6 @@ export const enableUseRefAccessWarning = false;
57
export const enableRecursiveCommitTraversal = false;
58
export const disableSchedulerTimeoutInWorkLoop = false;
59
export const enableSyncMicroTasks = false;
60
-export const enableNativeEventPriorityInference = false;
60
export const enableLazyContextPropagation = false;
61
62
// Flow magic to verify the exports of this file match the original version.
packages/shared/forks/ReactFeatureFlags.test-renderer.js
-1
@@ -57,7 +57,6 @@ export const enableUseRefAccessWarning = false;
57
export const enableRecursiveCommitTraversal = false;
58
export const disableSchedulerTimeoutInWorkLoop = false;
59
export const enableSyncMicroTasks = false;
60
-export const enableNativeEventPriorityInference = false;
60
export const enableLazyContextPropagation = false;
61
62
// Flow magic to verify the exports of this file match the original version.
packages/shared/forks/ReactFeatureFlags.test-renderer.native.js
-1
@@ -57,7 +57,6 @@ export const enableUseRefAccessWarning = false;
57
export const enableRecursiveCommitTraversal = false;
58
export const disableSchedulerTimeoutInWorkLoop = false;
59
export const enableSyncMicroTasks = false;
60
-export const enableNativeEventPriorityInference = false;
60
export const enableLazyContextPropagation = false;
61
62
// Flow magic to verify the exports of this file match the original version.
packages/shared/forks/ReactFeatureFlags.test-renderer.www.js
-1
@@ -57,7 +57,6 @@ export const enableUseRefAccessWarning = false;
57
export const enableRecursiveCommitTraversal = false;
58
export const disableSchedulerTimeoutInWorkLoop = false;
59
export const enableSyncMicroTasks = false;
60
-export const enableNativeEventPriorityInference = false;
60
export const enableLazyContextPropagation = false;
61
62
// Flow magic to verify the exports of this file match the original version.
packages/shared/forks/ReactFeatureFlags.testing.js
-1
@@ -57,7 +57,6 @@ export const enableUseRefAccessWarning = false;
57
export const enableRecursiveCommitTraversal = false;
58
export const disableSchedulerTimeoutInWorkLoop = false;
59
export const enableSyncMicroTasks = false;
60
-export const enableNativeEventPriorityInference = false;
60
export const enableLazyContextPropagation = false;
61
62
// Flow magic to verify the exports of this file match the original version.
packages/shared/forks/ReactFeatureFlags.testing.www.js
-1
@@ -57,7 +57,6 @@ export const enableUseRefAccessWarning = false;
57
export const enableRecursiveCommitTraversal = false;
58
export const disableSchedulerTimeoutInWorkLoop = false;
59
export const enableSyncMicroTasks = false;
60
-export const enableNativeEventPriorityInference = false;
60
export const enableLazyContextPropagation = false;
61
62
// Flow magic to verify the exports of this file match the original version.
packages/shared/forks/ReactFeatureFlags.www-dynamic.js
-1
@@ -56,5 +56,4 @@ export const enableUseRefAccessWarning = __VARIANT__;
56
export const enableProfilerNestedUpdateScheduledHook = __VARIANT__;
57
export const disableSchedulerTimeoutInWorkLoop = __VARIANT__;
58
export const enableSyncMicroTasks = __VARIANT__;
59
-export const enableNativeEventPriorityInference = __VARIANT__;
59
export const enableLazyContextPropagation = __VARIANT__;
packages/shared/forks/ReactFeatureFlags.www.js
-1
@@ -32,7 +32,6 @@ export const {
32
disableNativeComponentFrames,
33
disableSchedulerTimeoutInWorkLoop,
34
enableSyncMicroTasks,
35
- enableNativeEventPriorityInference,
35
enableLazyContextPropagation,
36
} = dynamicFeatureFlags;
37