@samitouri / QOS-React-2 / commits / 3ba5c87377

Remove Scheduler indirection (#21107)

* Bump version number * Remove Scheduler indirection I originally kept the React PriorityLevel and Scheduler PriorityLevel types separate in case there was a versioning mismatch between the two modules. However, it looks like we're going to keep the Scheduler module private in the short to medium term, and longer term the public interface will match postTask. So, I've removed the extra indirection (the switch statements that convert between the two types).

Andrew Clark committed Mar 28, 2021 at 16:13 UTC 3ba5c87377710e154351aebc818df3d33ee6a718
14 files changed +62 -215
packages/react-art/package.json
+2 -2
@@ -1,7 +1,7 @@
1 {
2 "name": "react-art",
3 "description": "React ART is a JavaScript library for drawing vector graphics using React. It provides declarative and reactive bindings to the ART library. Using the same declarative API you can render the output to either Canvas, SVG or VML (IE8).",
4 - "version": "17.0.2",
4 + "version": "17.0.3",
5 "main": "index.js",
6 "repository": {
7 "type": "git",
@@ -29,7 +29,7 @@
29 "scheduler": "^0.20.1"
30 },
31 "peerDependencies": {
32 - "react": "17.0.2"
32 + "react": "17.0.3"
33 },
34 "files": [
35 "LICENSE",
packages/react-devtools-scheduling-profiler/src/import-worker/__tests__/preprocessData-test.internal.js
+1 -1
@@ -517,7 +517,7 @@ describe(preprocessData, () => {
517 timestamp: 0.003,
518 },
519 {
520 - name: '--react-init-17.0.2',
520 + name: '--react-init-17.0.3',
521 timestamp: 0.004,
522 },
523 ],
packages/react-devtools-shared/src/backend/renderer.js
+12 -1
@@ -159,7 +159,7 @@ export function getInternalReactConstants(
159 // Technically these priority levels are invalid for versions before 16.9,
160 // but 16.9 is the first version to report priority level to DevTools,
161 // so we can avoid checking for earlier versions and support pre-16.9 canary releases in the process.
162 - const ReactPriorityLevels: ReactPriorityLevelsType = {
162 + let ReactPriorityLevels: ReactPriorityLevelsType = {
163 ImmediatePriority: 99,
164 UserBlockingPriority: 98,
165 NormalPriority: 97,
@@ -168,6 +168,17 @@ export function getInternalReactConstants(
168 NoPriority: 90,
169 };
170
171 + if (gt(version, '17.0.2')) {
172 + ReactPriorityLevels = {
173 + ImmediatePriority: 1,
174 + UserBlockingPriority: 2,
175 + NormalPriority: 3,
176 + LowPriority: 4,
177 + IdlePriority: 5,
178 + NoPriority: 0,
179 + };
180 + }
181 +
182 let ReactTypeOfWork: WorkTagMap = ((null: any): WorkTagMap);
183
184 // **********************************************************
packages/react-dom/package.json
+2 -2
@@ -1,6 +1,6 @@
1 {
2 "name": "react-dom",
3 - "version": "17.0.2",
3 + "version": "17.0.3",
4 "description": "React package for working with the DOM.",
5 "main": "index.js",
6 "repository": {
@@ -22,7 +22,7 @@
22 "scheduler": "^0.20.1"
23 },
24 "peerDependencies": {
25 - "react": "17.0.2"
25 + "react": "17.0.3"
26 },
27 "files": [
28 "LICENSE",
packages/react-is/package.json
+1 -1
@@ -1,6 +1,6 @@
1 {
2 "name": "react-is",
3 - "version": "17.0.2",
3 + "version": "17.0.3",
4 "description": "Brand checking of React Elements.",
5 "main": "index.js",
6 "repository": {
packages/react-reconciler/package.json
+1 -1
@@ -27,7 +27,7 @@
27 "node": ">=0.10.0"
28 },
29 "peerDependencies": {
30 - "react": "^17.0.2"
30 + "react": "^17.0.3"
31 },
32 "dependencies": {
33 "loose-envify": "^1.1.0",
packages/react-reconciler/src/ReactFiberHooks.new.js
-2
@@ -16,7 +16,6 @@ import type {
16 import type {Fiber, Dispatcher, HookType} from './ReactInternalTypes';
17 import type {Lanes, Lane} from './ReactFiberLane.new';
18 import type {HookFlags} from './ReactHookEffectTags';
19 -import type {ReactPriorityLevel} from './ReactInternalTypes';
19 import type {FiberRoot} from './ReactInternalTypes';
20 import type {OpaqueIDType} from './ReactFiberHostConfig';
21 import type {Cache} from './ReactFiberCacheComponent.new';
@@ -120,7 +119,6 @@ type Update<S, A> = {|
119 eagerReducer: ((S, A) => S) | null,
120 eagerState: S | null,
121 next: Update<S, A>,
123 - priority?: ReactPriorityLevel,
122 |};
123
124 export type UpdateQueue<S, A> = {|
packages/react-reconciler/src/ReactFiberHooks.old.js
-2
@@ -16,7 +16,6 @@ import type {
16 import type {Fiber, Dispatcher, HookType} from './ReactInternalTypes';
17 import type {Lanes, Lane} from './ReactFiberLane.old';
18 import type {HookFlags} from './ReactHookEffectTags';
19 -import type {ReactPriorityLevel} from './ReactInternalTypes';
19 import type {FiberRoot} from './ReactInternalTypes';
20 import type {OpaqueIDType} from './ReactFiberHostConfig';
21 import type {Cache} from './ReactFiberCacheComponent.old';
@@ -120,7 +119,6 @@ type Update<S, A> = {|
119 eagerReducer: ((S, A) => S) | null,
120 eagerState: S | null,
121 next: Update<S, A>,
123 - priority?: ReactPriorityLevel,
122 |};
123
124 export type UpdateQueue<S, A> = {|
packages/react-reconciler/src/ReactInternalTypes.js
-2
@@ -45,8 +45,6 @@ export type HookType =
45 | 'useOpaqueIdentifier'
46 | 'useCacheRefresh';
47
48 -export type ReactPriorityLevel = 99 | 98 | 97 | 96 | 95 | 90;
49 -
48 export type ContextDependency<T> = {
49 context: ReactContext<T>,
50 next: ContextDependency<mixed> | null,
packages/react-reconciler/src/SchedulerWithReactIntegration.new.js
+18 -97
@@ -7,10 +7,10 @@
7 * @flow
8 */
9
10 -import type {ReactPriorityLevel} from './ReactInternalTypes';
11 -
12 -// Intentionally not named imports because Rollup would use dynamic dispatch for
13 -// CommonJS interop named imports.
10 +// This module only exists as an ESM wrapper around the external CommonJS
11 +// Scheduler dependency. Notice that we're intentionally not using named imports
12 +// because Rollup would use dynamic dispatch for CommonJS interop named imports.
13 +// When we switch to ESM, we can delete this module.
14 import * as Scheduler from 'scheduler';
15 import {__interactionsRef} from 'scheduler/tracing';
16 import {enableSchedulerTracing} from 'shared/ReactFeatureFlags';
@@ -21,19 +21,18 @@ import {
21 setCurrentUpdatePriority,
22 } from './ReactEventPriorities.new';
23
24 -const {
25 - unstable_scheduleCallback: Scheduler_scheduleCallback,
26 - unstable_cancelCallback: Scheduler_cancelCallback,
27 - unstable_shouldYield: Scheduler_shouldYield,
28 - unstable_requestPaint: Scheduler_requestPaint,
29 - unstable_now: Scheduler_now,
30 - unstable_getCurrentPriorityLevel: Scheduler_getCurrentPriorityLevel,
31 - unstable_ImmediatePriority: Scheduler_ImmediatePriority,
32 - unstable_UserBlockingPriority: Scheduler_UserBlockingPriority,
33 - unstable_NormalPriority: Scheduler_NormalPriority,
34 - unstable_LowPriority: Scheduler_LowPriority,
35 - unstable_IdlePriority: Scheduler_IdlePriority,
36 -} = Scheduler;
24 +export const scheduleCallback = Scheduler.unstable_scheduleCallback;
25 +export const cancelCallback = Scheduler.unstable_cancelCallback;
26 +export const shouldYield = Scheduler.unstable_shouldYield;
27 +export const requestPaint = Scheduler.unstable_requestPaint;
28 +export const now = Scheduler.unstable_now;
29 +export const getCurrentPriorityLevel =
30 + Scheduler.unstable_getCurrentPriorityLevel;
31 +export const ImmediatePriority = Scheduler.unstable_ImmediatePriority;
32 +export const UserBlockingPriority = Scheduler.unstable_UserBlockingPriority;
33 +export const NormalPriority = Scheduler.unstable_NormalPriority;
34 +export const LowPriority = Scheduler.unstable_LowPriority;
35 +export const IdlePriority = Scheduler.unstable_IdlePriority;
36
37 if (enableSchedulerTracing) {
38 // Provide explicit error message when production+profiling bundle of e.g.
@@ -51,80 +50,9 @@ if (enableSchedulerTracing) {
50
51 export type SchedulerCallback = (isSync: boolean) => SchedulerCallback | null;
52
54 -type SchedulerCallbackOptions = {timeout?: number, ...};
55 -
56 -// Except for NoPriority, these correspond to Scheduler priorities. We use
57 -// ascending numbers so we can compare them like numbers. They start at 90 to
58 -// avoid clashing with Scheduler's priorities.
59 -export const ImmediatePriority: ReactPriorityLevel = 99;
60 -export const UserBlockingPriority: ReactPriorityLevel = 98;
61 -export const NormalPriority: ReactPriorityLevel = 97;
62 -export const LowPriority: ReactPriorityLevel = 96;
63 -export const IdlePriority: ReactPriorityLevel = 95;
64 -// NoPriority is the absence of priority. Also React-only.
65 -export const NoPriority: ReactPriorityLevel = 90;
66 -
67 -export const shouldYield = Scheduler_shouldYield;
68 -export const requestPaint =
69 - // Fall back gracefully if we're running an older version of Scheduler.
70 - Scheduler_requestPaint !== undefined ? Scheduler_requestPaint : () => {};
71 -
53 +// TODO: Move sync task queue to its own module.
54 let syncQueue: Array<SchedulerCallback> | null = null;
55 let isFlushingSyncQueue: boolean = false;
74 -const initialTimeMs: number = Scheduler_now();
75 -
76 -// If the initial timestamp is reasonably small, use Scheduler's `now` directly.
77 -// This will be the case for modern browsers that support `performance.now`. In
78 -// older browsers, Scheduler falls back to `Date.now`, which returns a Unix
79 -// timestamp. In that case, subtract the module initialization time to simulate
80 -// the behavior of performance.now and keep our times small enough to fit
81 -// within 32 bits.
82 -// TODO: Consider lifting this into Scheduler.
83 -export const now =
84 - initialTimeMs < 10000 ? Scheduler_now : () => Scheduler_now() - initialTimeMs;
85 -
86 -export function getCurrentPriorityLevel(): ReactPriorityLevel {
87 - switch (Scheduler_getCurrentPriorityLevel()) {
88 - case Scheduler_ImmediatePriority:
89 - return ImmediatePriority;
90 - case Scheduler_UserBlockingPriority:
91 - return UserBlockingPriority;
92 - case Scheduler_NormalPriority:
93 - return NormalPriority;
94 - case Scheduler_LowPriority:
95 - return LowPriority;
96 - case Scheduler_IdlePriority:
97 - return IdlePriority;
98 - default:
99 - invariant(false, 'Unknown priority level.');
100 - }
101 -}
102 -
103 -function reactPriorityToSchedulerPriority(reactPriorityLevel) {
104 - switch (reactPriorityLevel) {
105 - case ImmediatePriority:
106 - return Scheduler_ImmediatePriority;
107 - case UserBlockingPriority:
108 - return Scheduler_UserBlockingPriority;
109 - case NormalPriority:
110 - return Scheduler_NormalPriority;
111 - case LowPriority:
112 - return Scheduler_LowPriority;
113 - case IdlePriority:
114 - return Scheduler_IdlePriority;
115 - default:
116 - invariant(false, 'Unknown priority level.');
117 - }
118 -}
119 -
120 -export function scheduleCallback(
121 - reactPriorityLevel: ReactPriorityLevel,
122 - callback: SchedulerCallback,
123 - options: SchedulerCallbackOptions | void | null,
124 -) {
125 - const priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
126 - return Scheduler_scheduleCallback(priorityLevel, callback, options);
127 -}
56
57 export function scheduleSyncCallback(callback: SchedulerCallback) {
58 // Push this callback into an internal queue. We'll flush these either in
@@ -138,10 +66,6 @@ export function scheduleSyncCallback(callback: SchedulerCallback) {
66 }
67 }
68
141 -export function cancelCallback(callbackNode: mixed) {
142 - Scheduler_cancelCallback(callbackNode);
143 -}
144 -
69 export function flushSyncCallbackQueue() {
70 if (!isFlushingSyncQueue && syncQueue !== null) {
71 // Prevent re-entrancy.
@@ -167,10 +91,7 @@ export function flushSyncCallbackQueue() {
91 syncQueue = syncQueue.slice(i + 1);
92 }
93 // Resume flushing in the next tick
170 - Scheduler_scheduleCallback(
171 - Scheduler_ImmediatePriority,
172 - flushSyncCallbackQueue,
173 - );
94 + scheduleCallback(ImmediatePriority, flushSyncCallbackQueue);
95 throw error;
96 } finally {
97 setCurrentUpdatePriority(previousUpdatePriority);
packages/react-reconciler/src/SchedulerWithReactIntegration.old.js
+18 -97
@@ -7,10 +7,10 @@
7 * @flow
8 */
9
10 -import type {ReactPriorityLevel} from './ReactInternalTypes';
11 -
12 -// Intentionally not named imports because Rollup would use dynamic dispatch for
13 -// CommonJS interop named imports.
10 +// This module only exists as an ESM wrapper around the external CommonJS
11 +// Scheduler dependency. Notice that we're intentionally not using named imports
12 +// because Rollup would use dynamic dispatch for CommonJS interop named imports.
13 +// When we switch to ESM, we can delete this module.
14 import * as Scheduler from 'scheduler';
15 import {__interactionsRef} from 'scheduler/tracing';
16 import {enableSchedulerTracing} from 'shared/ReactFeatureFlags';
@@ -21,19 +21,18 @@ import {
21 setCurrentUpdatePriority,
22 } from './ReactEventPriorities.old';
23
24 -const {
25 - unstable_scheduleCallback: Scheduler_scheduleCallback,
26 - unstable_cancelCallback: Scheduler_cancelCallback,
27 - unstable_shouldYield: Scheduler_shouldYield,
28 - unstable_requestPaint: Scheduler_requestPaint,
29 - unstable_now: Scheduler_now,
30 - unstable_getCurrentPriorityLevel: Scheduler_getCurrentPriorityLevel,
31 - unstable_ImmediatePriority: Scheduler_ImmediatePriority,
32 - unstable_UserBlockingPriority: Scheduler_UserBlockingPriority,
33 - unstable_NormalPriority: Scheduler_NormalPriority,
34 - unstable_LowPriority: Scheduler_LowPriority,
35 - unstable_IdlePriority: Scheduler_IdlePriority,
36 -} = Scheduler;
24 +export const scheduleCallback = Scheduler.unstable_scheduleCallback;
25 +export const cancelCallback = Scheduler.unstable_cancelCallback;
26 +export const shouldYield = Scheduler.unstable_shouldYield;
27 +export const requestPaint = Scheduler.unstable_requestPaint;
28 +export const now = Scheduler.unstable_now;
29 +export const getCurrentPriorityLevel =
30 + Scheduler.unstable_getCurrentPriorityLevel;
31 +export const ImmediatePriority = Scheduler.unstable_ImmediatePriority;
32 +export const UserBlockingPriority = Scheduler.unstable_UserBlockingPriority;
33 +export const NormalPriority = Scheduler.unstable_NormalPriority;
34 +export const LowPriority = Scheduler.unstable_LowPriority;
35 +export const IdlePriority = Scheduler.unstable_IdlePriority;
36
37 if (enableSchedulerTracing) {
38 // Provide explicit error message when production+profiling bundle of e.g.
@@ -51,80 +50,9 @@ if (enableSchedulerTracing) {
50
51 export type SchedulerCallback = (isSync: boolean) => SchedulerCallback | null;
52
54 -type SchedulerCallbackOptions = {timeout?: number, ...};
55 -
56 -// Except for NoPriority, these correspond to Scheduler priorities. We use
57 -// ascending numbers so we can compare them like numbers. They start at 90 to
58 -// avoid clashing with Scheduler's priorities.
59 -export const ImmediatePriority: ReactPriorityLevel = 99;
60 -export const UserBlockingPriority: ReactPriorityLevel = 98;
61 -export const NormalPriority: ReactPriorityLevel = 97;
62 -export const LowPriority: ReactPriorityLevel = 96;
63 -export const IdlePriority: ReactPriorityLevel = 95;
64 -// NoPriority is the absence of priority. Also React-only.
65 -export const NoPriority: ReactPriorityLevel = 90;
66 -
67 -export const shouldYield = Scheduler_shouldYield;
68 -export const requestPaint =
69 - // Fall back gracefully if we're running an older version of Scheduler.
70 - Scheduler_requestPaint !== undefined ? Scheduler_requestPaint : () => {};
71 -
53 +// TODO: Move sync task queue to its own module.
54 let syncQueue: Array<SchedulerCallback> | null = null;
55 let isFlushingSyncQueue: boolean = false;
74 -const initialTimeMs: number = Scheduler_now();
75 -
76 -// If the initial timestamp is reasonably small, use Scheduler's `now` directly.
77 -// This will be the case for modern browsers that support `performance.now`. In
78 -// older browsers, Scheduler falls back to `Date.now`, which returns a Unix
79 -// timestamp. In that case, subtract the module initialization time to simulate
80 -// the behavior of performance.now and keep our times small enough to fit
81 -// within 32 bits.
82 -// TODO: Consider lifting this into Scheduler.
83 -export const now =
84 - initialTimeMs < 10000 ? Scheduler_now : () => Scheduler_now() - initialTimeMs;
85 -
86 -export function getCurrentPriorityLevel(): ReactPriorityLevel {
87 - switch (Scheduler_getCurrentPriorityLevel()) {
88 - case Scheduler_ImmediatePriority:
89 - return ImmediatePriority;
90 - case Scheduler_UserBlockingPriority:
91 - return UserBlockingPriority;
92 - case Scheduler_NormalPriority:
93 - return NormalPriority;
94 - case Scheduler_LowPriority:
95 - return LowPriority;
96 - case Scheduler_IdlePriority:
97 - return IdlePriority;
98 - default:
99 - invariant(false, 'Unknown priority level.');
100 - }
101 -}
102 -
103 -function reactPriorityToSchedulerPriority(reactPriorityLevel) {
104 - switch (reactPriorityLevel) {
105 - case ImmediatePriority:
106 - return Scheduler_ImmediatePriority;
107 - case UserBlockingPriority:
108 - return Scheduler_UserBlockingPriority;
109 - case NormalPriority:
110 - return Scheduler_NormalPriority;
111 - case LowPriority:
112 - return Scheduler_LowPriority;
113 - case IdlePriority:
114 - return Scheduler_IdlePriority;
115 - default:
116 - invariant(false, 'Unknown priority level.');
117 - }
118 -}
119 -
120 -export function scheduleCallback(
121 - reactPriorityLevel: ReactPriorityLevel,
122 - callback: SchedulerCallback,
123 - options: SchedulerCallbackOptions | void | null,
124 -) {
125 - const priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
126 - return Scheduler_scheduleCallback(priorityLevel, callback, options);
127 -}
56
57 export function scheduleSyncCallback(callback: SchedulerCallback) {
58 // Push this callback into an internal queue. We'll flush these either in
@@ -138,10 +66,6 @@ export function scheduleSyncCallback(callback: SchedulerCallback) {
66 }
67 }
68
141 -export function cancelCallback(callbackNode: mixed) {
142 - Scheduler_cancelCallback(callbackNode);
143 -}
144 -
69 export function flushSyncCallbackQueue() {
70 if (!isFlushingSyncQueue && syncQueue !== null) {
71 // Prevent re-entrancy.
@@ -167,10 +91,7 @@ export function flushSyncCallbackQueue() {
91 syncQueue = syncQueue.slice(i + 1);
92 }
93 // Resume flushing in the next tick
170 - Scheduler_scheduleCallback(
171 - Scheduler_ImmediatePriority,
172 - flushSyncCallbackQueue,
173 - );
94 + scheduleCallback(ImmediatePriority, flushSyncCallbackQueue);
95 throw error;
96 } finally {
97 setCurrentUpdatePriority(previousUpdatePriority);
packages/react-test-renderer/package.json
+3 -3
@@ -1,6 +1,6 @@
1 {
2 "name": "react-test-renderer",
3 - "version": "17.0.2",
3 + "version": "17.0.3",
4 "description": "React package for snapshot testing.",
5 "main": "index.js",
6 "repository": {
@@ -20,12 +20,12 @@
20 "homepage": "https://reactjs.org/",
21 "dependencies": {
22 "object-assign": "^4.1.1",
23 - "react-is": "^17.0.2",
23 + "react-is": "^17.0.3",
24 "react-shallow-renderer": "^16.13.1",
25 "scheduler": "^0.20.1"
26 },
27 "peerDependencies": {
28 - "react": "17.0.2"
28 + "react": "17.0.3"
29 },
30 "files": [
31 "LICENSE",
packages/react/package.json
+1 -1
@@ -4,7 +4,7 @@
4 "keywords": [
5 "react"
6 ],
7 - "version": "17.0.2",
7 + "version": "17.0.3",
8 "homepage": "https://reactjs.org/",
9 "bugs": "https://github.com/facebook/react/issues",
10 "license": "MIT",
packages/shared/ReactVersion.js
+3 -3
@@ -7,7 +7,7 @@
7
8 // TODO: this is special because it gets imported during build.
9 //
10 -// TODO: 17.0.2 has not been released to NPM;
10 +// TODO: 17.0.3 has not been released to NPM;
11 // It exists as a placeholder so that DevTools can support work tag changes between releases.
12 -// When we next publish a release (either 17.0.2 or 17.1.0), update the matching TODO in backend/renderer.js
13 -export default '17.0.2';
12 +// When we next publish a release (either 17.0.3 or 17.1.0), update the matching TODO in backend/renderer.js
13 +export default '17.0.3';