Skip to content

Commit 41e62e7

Browse files
committed
Remove runWithPriority internally
1 parent 431e76e commit 41e62e7

8 files changed

+45
-166
lines changed

Diff for: packages/react-dom/src/events/ReactDOMEventListener.js

+1-20
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
1212
import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig';
1313
import type {DOMEventName} from '../events/DOMEventNames';
1414

15-
// Intentionally not named imports because Rollup would use dynamic dispatch for
16-
// CommonJS interop named imports.
17-
import * as Scheduler from 'scheduler';
18-
1915
import {
2016
isReplayableDiscreteEvent,
2117
queueDiscreteEvent,
@@ -89,11 +85,6 @@ const getCurrentPriorityLevel = enableNewReconciler
8985
? getCurrentPriorityLevel_new
9086
: getCurrentPriorityLevel_old;
9187

92-
const {
93-
unstable_UserBlockingPriority: UserBlockingPriority,
94-
unstable_runWithPriority: runWithPriority,
95-
} = Scheduler;
96-
9788
// TODO: can we stop exporting these?
9889
export let _enabled = true;
9990

@@ -178,18 +169,8 @@ function dispatchContinuousEvent(
178169
) {
179170
const previousPriority = getCurrentUpdateLanePriority();
180171
try {
181-
// TODO: Double wrapping is necessary while we decouple Scheduler priority.
182172
setCurrentUpdateLanePriority(InputContinuousLanePriority);
183-
runWithPriority(
184-
UserBlockingPriority,
185-
dispatchEvent.bind(
186-
null,
187-
domEventName,
188-
eventSystemFlags,
189-
container,
190-
nativeEvent,
191-
),
192-
);
173+
dispatchEvent(domEventName, eventSystemFlags, container, nativeEvent);
193174
} finally {
194175
setCurrentUpdateLanePriority(previousPriority);
195176
}

Diff for: packages/react-reconciler/src/ReactFiberHooks.new.js

+10-27
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,6 @@ import {
8787
markWorkInProgressReceivedUpdate,
8888
checkIfWorkInProgressReceivedUpdate,
8989
} from './ReactFiberBeginWork.new';
90-
import {
91-
UserBlockingPriority,
92-
NormalPriority,
93-
runWithPriority,
94-
getCurrentPriorityLevel,
95-
} from './SchedulerWithReactIntegration.new';
9690
import {getIsHydrating} from './ReactFiberHydrationContext.new';
9791
import {
9892
makeClientId,
@@ -1711,38 +1705,27 @@ function rerenderDeferredValue<T>(value: T): T {
17111705
}
17121706

17131707
function startTransition(setPending, callback) {
1714-
const priorityLevel = getCurrentPriorityLevel();
17151708
const previousLanePriority = getCurrentUpdateLanePriority();
17161709
setCurrentUpdateLanePriority(
17171710
higherLanePriority(previousLanePriority, InputContinuousLanePriority),
17181711
);
17191712

1720-
runWithPriority(
1721-
priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel,
1722-
() => {
1723-
setPending(true);
1724-
},
1725-
);
1713+
setPending(true);
17261714

17271715
// TODO: Can remove this. Was only necessary because we used to give
17281716
// different behavior to transitions without a config object. Now they are
17291717
// all treated the same.
17301718
setCurrentUpdateLanePriority(DefaultLanePriority);
17311719

1732-
runWithPriority(
1733-
priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
1734-
() => {
1735-
const prevTransition = ReactCurrentBatchConfig.transition;
1736-
ReactCurrentBatchConfig.transition = 1;
1737-
try {
1738-
setPending(false);
1739-
callback();
1740-
} finally {
1741-
setCurrentUpdateLanePriority(previousLanePriority);
1742-
ReactCurrentBatchConfig.transition = prevTransition;
1743-
}
1744-
},
1745-
);
1720+
const prevTransition = ReactCurrentBatchConfig.transition;
1721+
ReactCurrentBatchConfig.transition = 1;
1722+
try {
1723+
setPending(false);
1724+
callback();
1725+
} finally {
1726+
setCurrentUpdateLanePriority(previousLanePriority);
1727+
ReactCurrentBatchConfig.transition = prevTransition;
1728+
}
17461729
}
17471730

17481731
function mountTransition(): [(() => void) => void, boolean] {

Diff for: packages/react-reconciler/src/ReactFiberHooks.old.js

+10-27
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,6 @@ import {
8787
markWorkInProgressReceivedUpdate,
8888
checkIfWorkInProgressReceivedUpdate,
8989
} from './ReactFiberBeginWork.old';
90-
import {
91-
UserBlockingPriority,
92-
NormalPriority,
93-
runWithPriority,
94-
getCurrentPriorityLevel,
95-
} from './SchedulerWithReactIntegration.old';
9690
import {getIsHydrating} from './ReactFiberHydrationContext.old';
9791
import {
9892
makeClientId,
@@ -1711,38 +1705,27 @@ function rerenderDeferredValue<T>(value: T): T {
17111705
}
17121706

17131707
function startTransition(setPending, callback) {
1714-
const priorityLevel = getCurrentPriorityLevel();
17151708
const previousLanePriority = getCurrentUpdateLanePriority();
17161709
setCurrentUpdateLanePriority(
17171710
higherLanePriority(previousLanePriority, InputContinuousLanePriority),
17181711
);
17191712

1720-
runWithPriority(
1721-
priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel,
1722-
() => {
1723-
setPending(true);
1724-
},
1725-
);
1713+
setPending(true);
17261714

17271715
// TODO: Can remove this. Was only necessary because we used to give
17281716
// different behavior to transitions without a config object. Now they are
17291717
// all treated the same.
17301718
setCurrentUpdateLanePriority(DefaultLanePriority);
17311719

1732-
runWithPriority(
1733-
priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
1734-
() => {
1735-
const prevTransition = ReactCurrentBatchConfig.transition;
1736-
ReactCurrentBatchConfig.transition = 1;
1737-
try {
1738-
setPending(false);
1739-
callback();
1740-
} finally {
1741-
setCurrentUpdateLanePriority(previousLanePriority);
1742-
ReactCurrentBatchConfig.transition = prevTransition;
1743-
}
1744-
},
1745-
);
1720+
const prevTransition = ReactCurrentBatchConfig.transition;
1721+
ReactCurrentBatchConfig.transition = 1;
1722+
try {
1723+
setPending(false);
1724+
callback();
1725+
} finally {
1726+
setCurrentUpdateLanePriority(previousLanePriority);
1727+
ReactCurrentBatchConfig.transition = prevTransition;
1728+
}
17461729
}
17471730

17481731
function mountTransition(): [(() => void) => void, boolean] {

Diff for: packages/react-reconciler/src/ReactFiberWorkLoop.new.js

+6-13
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import {
4141
scheduleCallback,
4242
cancelCallback,
4343
getCurrentPriorityLevel,
44-
runWithPriority,
4544
shouldYield,
4645
requestPaint,
4746
now,
@@ -1124,7 +1123,7 @@ export function deferredUpdates<A>(fn: () => A): A {
11241123
const previousLanePriority = getCurrentUpdateLanePriority();
11251124
try {
11261125
setCurrentUpdateLanePriority(DefaultLanePriority);
1127-
return runWithPriority(NormalSchedulerPriority, fn);
1126+
return fn();
11281127
} finally {
11291128
setCurrentUpdateLanePriority(previousLanePriority);
11301129
}
@@ -1176,7 +1175,7 @@ export function batchedEventUpdates<A, R>(fn: A => R, a: A): R {
11761175
}
11771176

11781177
export function discreteUpdates<A, B, C, D, R>(
1179-
fn: (A, B, C) => R,
1178+
fn: (A, B, C, D) => R,
11801179
a: A,
11811180
b: B,
11821181
c: C,
@@ -1188,10 +1187,7 @@ export function discreteUpdates<A, B, C, D, R>(
11881187
const previousLanePriority = getCurrentUpdateLanePriority();
11891188
try {
11901189
setCurrentUpdateLanePriority(InputDiscreteLanePriority);
1191-
return runWithPriority(
1192-
UserBlockingSchedulerPriority,
1193-
fn.bind(null, a, b, c, d),
1194-
);
1190+
return fn(a, b, c, d);
11951191
} finally {
11961192
setCurrentUpdateLanePriority(previousLanePriority);
11971193
executionContext = prevExecutionContext;
@@ -1237,7 +1233,7 @@ export function flushSync<A, R>(fn: A => R, a: A): R {
12371233
try {
12381234
setCurrentUpdateLanePriority(SyncLanePriority);
12391235
if (fn) {
1240-
return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a));
1236+
return fn(a);
12411237
} else {
12421238
return (undefined: $FlowFixMe);
12431239
}
@@ -1257,7 +1253,7 @@ export function flushControlled(fn: () => mixed): void {
12571253
const previousLanePriority = getCurrentUpdateLanePriority();
12581254
try {
12591255
setCurrentUpdateLanePriority(SyncLanePriority);
1260-
runWithPriority(ImmediateSchedulerPriority, fn);
1256+
fn();
12611257
} finally {
12621258
setCurrentUpdateLanePriority(previousLanePriority);
12631259

@@ -1753,10 +1749,7 @@ function commitRoot(root) {
17531749
const previousUpdateLanePriority = getCurrentUpdateLanePriority();
17541750
try {
17551751
setCurrentUpdateLanePriority(SyncLanePriority);
1756-
runWithPriority(
1757-
ImmediateSchedulerPriority,
1758-
commitRootImpl.bind(null, root, previousUpdateLanePriority),
1759-
);
1752+
commitRootImpl(root, previousUpdateLanePriority);
17601753
} finally {
17611754
setCurrentUpdateLanePriority(previousUpdateLanePriority);
17621755
}

Diff for: packages/react-reconciler/src/ReactFiberWorkLoop.old.js

+6-13
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import {
4141
scheduleCallback,
4242
cancelCallback,
4343
getCurrentPriorityLevel,
44-
runWithPriority,
4544
shouldYield,
4645
requestPaint,
4746
now,
@@ -1124,7 +1123,7 @@ export function deferredUpdates<A>(fn: () => A): A {
11241123
const previousLanePriority = getCurrentUpdateLanePriority();
11251124
try {
11261125
setCurrentUpdateLanePriority(DefaultLanePriority);
1127-
return runWithPriority(NormalSchedulerPriority, fn);
1126+
return fn();
11281127
} finally {
11291128
setCurrentUpdateLanePriority(previousLanePriority);
11301129
}
@@ -1176,7 +1175,7 @@ export function batchedEventUpdates<A, R>(fn: A => R, a: A): R {
11761175
}
11771176

11781177
export function discreteUpdates<A, B, C, D, R>(
1179-
fn: (A, B, C) => R,
1178+
fn: (A, B, C, D) => R,
11801179
a: A,
11811180
b: B,
11821181
c: C,
@@ -1188,10 +1187,7 @@ export function discreteUpdates<A, B, C, D, R>(
11881187
const previousLanePriority = getCurrentUpdateLanePriority();
11891188
try {
11901189
setCurrentUpdateLanePriority(InputDiscreteLanePriority);
1191-
return runWithPriority(
1192-
UserBlockingSchedulerPriority,
1193-
fn.bind(null, a, b, c, d),
1194-
);
1190+
return fn(a, b, c, d);
11951191
} finally {
11961192
setCurrentUpdateLanePriority(previousLanePriority);
11971193
executionContext = prevExecutionContext;
@@ -1237,7 +1233,7 @@ export function flushSync<A, R>(fn: A => R, a: A): R {
12371233
try {
12381234
setCurrentUpdateLanePriority(SyncLanePriority);
12391235
if (fn) {
1240-
return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a));
1236+
return fn(a);
12411237
} else {
12421238
return (undefined: $FlowFixMe);
12431239
}
@@ -1257,7 +1253,7 @@ export function flushControlled(fn: () => mixed): void {
12571253
const previousLanePriority = getCurrentUpdateLanePriority();
12581254
try {
12591255
setCurrentUpdateLanePriority(SyncLanePriority);
1260-
runWithPriority(ImmediateSchedulerPriority, fn);
1256+
fn();
12611257
} finally {
12621258
setCurrentUpdateLanePriority(previousLanePriority);
12631259

@@ -1753,10 +1749,7 @@ function commitRoot(root) {
17531749
const previousUpdateLanePriority = getCurrentUpdateLanePriority();
17541750
try {
17551751
setCurrentUpdateLanePriority(SyncLanePriority);
1756-
runWithPriority(
1757-
ImmediateSchedulerPriority,
1758-
commitRootImpl.bind(null, root, previousUpdateLanePriority),
1759-
);
1752+
commitRootImpl(root, previousUpdateLanePriority);
17601753
} finally {
17611754
setCurrentUpdateLanePriority(previousUpdateLanePriority);
17621755
}

Diff for: packages/react-reconciler/src/SchedulerWithReactIntegration.new.js

+6-17
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
import {scheduleMicrotask, supportsMicrotasks} from './ReactFiberHostConfig';
2727

2828
const {
29-
unstable_runWithPriority: Scheduler_runWithPriority,
3029
unstable_scheduleCallback: Scheduler_scheduleCallback,
3130
unstable_cancelCallback: Scheduler_cancelCallback,
3231
unstable_shouldYield: Scheduler_shouldYield,
@@ -123,14 +122,6 @@ function reactPriorityToSchedulerPriority(reactPriorityLevel) {
123122
}
124123
}
125124

126-
export function runWithPriority<T>(
127-
reactPriorityLevel: ReactPriorityLevel,
128-
fn: () => T,
129-
): T {
130-
const priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
131-
return Scheduler_runWithPriority(priorityLevel, fn);
132-
}
133-
134125
export function scheduleCallback(
135126
reactPriorityLevel: ReactPriorityLevel,
136127
callback: SchedulerCallback,
@@ -188,14 +179,12 @@ function flushSyncCallbackQueueImpl() {
188179
const isSync = true;
189180
const queue = syncQueue;
190181
setCurrentUpdateLanePriority(SyncLanePriority);
191-
runWithPriority(ImmediatePriority, () => {
192-
for (; i < queue.length; i++) {
193-
let callback = queue[i];
194-
do {
195-
callback = callback(isSync);
196-
} while (callback !== null);
197-
}
198-
});
182+
for (; i < queue.length; i++) {
183+
let callback = queue[i];
184+
do {
185+
callback = callback(isSync);
186+
} while (callback !== null);
187+
}
199188
syncQueue = null;
200189
} catch (error) {
201190
// If something throws, leave the remaining callbacks on the queue.

Diff for: packages/react-reconciler/src/SchedulerWithReactIntegration.old.js

+6-17
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
import {scheduleMicrotask, supportsMicrotasks} from './ReactFiberHostConfig';
2727

2828
const {
29-
unstable_runWithPriority: Scheduler_runWithPriority,
3029
unstable_scheduleCallback: Scheduler_scheduleCallback,
3130
unstable_cancelCallback: Scheduler_cancelCallback,
3231
unstable_shouldYield: Scheduler_shouldYield,
@@ -123,14 +122,6 @@ function reactPriorityToSchedulerPriority(reactPriorityLevel) {
123122
}
124123
}
125124

126-
export function runWithPriority<T>(
127-
reactPriorityLevel: ReactPriorityLevel,
128-
fn: () => T,
129-
): T {
130-
const priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
131-
return Scheduler_runWithPriority(priorityLevel, fn);
132-
}
133-
134125
export function scheduleCallback(
135126
reactPriorityLevel: ReactPriorityLevel,
136127
callback: SchedulerCallback,
@@ -188,14 +179,12 @@ function flushSyncCallbackQueueImpl() {
188179
const isSync = true;
189180
const queue = syncQueue;
190181
setCurrentUpdateLanePriority(SyncLanePriority);
191-
runWithPriority(ImmediatePriority, () => {
192-
for (; i < queue.length; i++) {
193-
let callback = queue[i];
194-
do {
195-
callback = callback(isSync);
196-
} while (callback !== null);
197-
}
198-
});
182+
for (; i < queue.length; i++) {
183+
let callback = queue[i];
184+
do {
185+
callback = callback(isSync);
186+
} while (callback !== null);
187+
}
199188
syncQueue = null;
200189
} catch (error) {
201190
// If something throws, leave the remaining callbacks on the queue.

0 commit comments

Comments
 (0)