Skip to content

Commit 3ba5c87

Browse files
authored
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).
1 parent 46b68ea commit 3ba5c87

File tree

14 files changed

+62
-215
lines changed

14 files changed

+62
-215
lines changed

packages/react-art/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-art",
33
"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",
55
"main": "index.js",
66
"repository": {
77
"type": "git",
@@ -29,7 +29,7 @@
2929
"scheduler": "^0.20.1"
3030
},
3131
"peerDependencies": {
32-
"react": "17.0.2"
32+
"react": "17.0.3"
3333
},
3434
"files": [
3535
"LICENSE",

packages/react-devtools-scheduling-profiler/src/import-worker/__tests__/preprocessData-test.internal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ describe(preprocessData, () => {
517517
timestamp: 0.003,
518518
},
519519
{
520-
name: '--react-init-17.0.2',
520+
name: '--react-init-17.0.3',
521521
timestamp: 0.004,
522522
},
523523
],

packages/react-devtools-shared/src/backend/renderer.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export function getInternalReactConstants(
159159
// Technically these priority levels are invalid for versions before 16.9,
160160
// but 16.9 is the first version to report priority level to DevTools,
161161
// 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 = {
163163
ImmediatePriority: 99,
164164
UserBlockingPriority: 98,
165165
NormalPriority: 97,
@@ -168,6 +168,17 @@ export function getInternalReactConstants(
168168
NoPriority: 90,
169169
};
170170

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+
171182
let ReactTypeOfWork: WorkTagMap = ((null: any): WorkTagMap);
172183

173184
// **********************************************************

packages/react-dom/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-dom",
3-
"version": "17.0.2",
3+
"version": "17.0.3",
44
"description": "React package for working with the DOM.",
55
"main": "index.js",
66
"repository": {
@@ -22,7 +22,7 @@
2222
"scheduler": "^0.20.1"
2323
},
2424
"peerDependencies": {
25-
"react": "17.0.2"
25+
"react": "17.0.3"
2626
},
2727
"files": [
2828
"LICENSE",

packages/react-is/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-is",
3-
"version": "17.0.2",
3+
"version": "17.0.3",
44
"description": "Brand checking of React Elements.",
55
"main": "index.js",
66
"repository": {

packages/react-reconciler/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"node": ">=0.10.0"
2828
},
2929
"peerDependencies": {
30-
"react": "^17.0.2"
30+
"react": "^17.0.3"
3131
},
3232
"dependencies": {
3333
"loose-envify": "^1.1.0",

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import type {
1616
import type {Fiber, Dispatcher, HookType} from './ReactInternalTypes';
1717
import type {Lanes, Lane} from './ReactFiberLane.new';
1818
import type {HookFlags} from './ReactHookEffectTags';
19-
import type {ReactPriorityLevel} from './ReactInternalTypes';
2019
import type {FiberRoot} from './ReactInternalTypes';
2120
import type {OpaqueIDType} from './ReactFiberHostConfig';
2221
import type {Cache} from './ReactFiberCacheComponent.new';
@@ -120,7 +119,6 @@ type Update<S, A> = {|
120119
eagerReducer: ((S, A) => S) | null,
121120
eagerState: S | null,
122121
next: Update<S, A>,
123-
priority?: ReactPriorityLevel,
124122
|};
125123

126124
export type UpdateQueue<S, A> = {|

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import type {
1616
import type {Fiber, Dispatcher, HookType} from './ReactInternalTypes';
1717
import type {Lanes, Lane} from './ReactFiberLane.old';
1818
import type {HookFlags} from './ReactHookEffectTags';
19-
import type {ReactPriorityLevel} from './ReactInternalTypes';
2019
import type {FiberRoot} from './ReactInternalTypes';
2120
import type {OpaqueIDType} from './ReactFiberHostConfig';
2221
import type {Cache} from './ReactFiberCacheComponent.old';
@@ -120,7 +119,6 @@ type Update<S, A> = {|
120119
eagerReducer: ((S, A) => S) | null,
121120
eagerState: S | null,
122121
next: Update<S, A>,
123-
priority?: ReactPriorityLevel,
124122
|};
125123

126124
export type UpdateQueue<S, A> = {|

packages/react-reconciler/src/ReactInternalTypes.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ export type HookType =
4545
| 'useOpaqueIdentifier'
4646
| 'useCacheRefresh';
4747

48-
export type ReactPriorityLevel = 99 | 98 | 97 | 96 | 95 | 90;
49-
5048
export type ContextDependency<T> = {
5149
context: ReactContext<T>,
5250
next: ContextDependency<mixed> | null,

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

Lines changed: 18 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
* @flow
88
*/
99

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.
1414
import * as Scheduler from 'scheduler';
1515
import {__interactionsRef} from 'scheduler/tracing';
1616
import {enableSchedulerTracing} from 'shared/ReactFeatureFlags';
@@ -21,19 +21,18 @@ import {
2121
setCurrentUpdatePriority,
2222
} from './ReactEventPriorities.new';
2323

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;
3736

3837
if (enableSchedulerTracing) {
3938
// Provide explicit error message when production+profiling bundle of e.g.
@@ -51,80 +50,9 @@ if (enableSchedulerTracing) {
5150

5251
export type SchedulerCallback = (isSync: boolean) => SchedulerCallback | null;
5352

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.
7254
let syncQueue: Array<SchedulerCallback> | null = null;
7355
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-
}
12856

12957
export function scheduleSyncCallback(callback: SchedulerCallback) {
13058
// Push this callback into an internal queue. We'll flush these either in
@@ -138,10 +66,6 @@ export function scheduleSyncCallback(callback: SchedulerCallback) {
13866
}
13967
}
14068

141-
export function cancelCallback(callbackNode: mixed) {
142-
Scheduler_cancelCallback(callbackNode);
143-
}
144-
14569
export function flushSyncCallbackQueue() {
14670
if (!isFlushingSyncQueue && syncQueue !== null) {
14771
// Prevent re-entrancy.
@@ -167,10 +91,7 @@ export function flushSyncCallbackQueue() {
16791
syncQueue = syncQueue.slice(i + 1);
16892
}
16993
// Resume flushing in the next tick
170-
Scheduler_scheduleCallback(
171-
Scheduler_ImmediatePriority,
172-
flushSyncCallbackQueue,
173-
);
94+
scheduleCallback(ImmediatePriority, flushSyncCallbackQueue);
17495
throw error;
17596
} finally {
17697
setCurrentUpdatePriority(previousUpdatePriority);

0 commit comments

Comments
 (0)