Skip to content

Commit

Permalink
Remove runWithPriority internally
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii committed Mar 8, 2021
1 parent 431e76e commit 41e62e7
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 166 deletions.
21 changes: 1 addition & 20 deletions packages/react-dom/src/events/ReactDOMEventListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig';
import type {DOMEventName} from '../events/DOMEventNames';

// Intentionally not named imports because Rollup would use dynamic dispatch for
// CommonJS interop named imports.
import * as Scheduler from 'scheduler';

import {
isReplayableDiscreteEvent,
queueDiscreteEvent,
Expand Down Expand Up @@ -89,11 +85,6 @@ const getCurrentPriorityLevel = enableNewReconciler
? getCurrentPriorityLevel_new
: getCurrentPriorityLevel_old;

const {
unstable_UserBlockingPriority: UserBlockingPriority,
unstable_runWithPriority: runWithPriority,
} = Scheduler;

// TODO: can we stop exporting these?
export let _enabled = true;

Expand Down Expand Up @@ -178,18 +169,8 @@ function dispatchContinuousEvent(
) {
const previousPriority = getCurrentUpdateLanePriority();
try {
// TODO: Double wrapping is necessary while we decouple Scheduler priority.
setCurrentUpdateLanePriority(InputContinuousLanePriority);
runWithPriority(
UserBlockingPriority,
dispatchEvent.bind(
null,
domEventName,
eventSystemFlags,
container,
nativeEvent,
),
);
dispatchEvent(domEventName, eventSystemFlags, container, nativeEvent);
} finally {
setCurrentUpdateLanePriority(previousPriority);
}
Expand Down
37 changes: 10 additions & 27 deletions packages/react-reconciler/src/ReactFiberHooks.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,6 @@ import {
markWorkInProgressReceivedUpdate,
checkIfWorkInProgressReceivedUpdate,
} from './ReactFiberBeginWork.new';
import {
UserBlockingPriority,
NormalPriority,
runWithPriority,
getCurrentPriorityLevel,
} from './SchedulerWithReactIntegration.new';
import {getIsHydrating} from './ReactFiberHydrationContext.new';
import {
makeClientId,
Expand Down Expand Up @@ -1711,38 +1705,27 @@ function rerenderDeferredValue<T>(value: T): T {
}

function startTransition(setPending, callback) {
const priorityLevel = getCurrentPriorityLevel();
const previousLanePriority = getCurrentUpdateLanePriority();
setCurrentUpdateLanePriority(
higherLanePriority(previousLanePriority, InputContinuousLanePriority),
);

runWithPriority(
priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel,
() => {
setPending(true);
},
);
setPending(true);

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

runWithPriority(
priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
() => {
const prevTransition = ReactCurrentBatchConfig.transition;
ReactCurrentBatchConfig.transition = 1;
try {
setPending(false);
callback();
} finally {
setCurrentUpdateLanePriority(previousLanePriority);
ReactCurrentBatchConfig.transition = prevTransition;
}
},
);
const prevTransition = ReactCurrentBatchConfig.transition;
ReactCurrentBatchConfig.transition = 1;
try {
setPending(false);
callback();
} finally {
setCurrentUpdateLanePriority(previousLanePriority);
ReactCurrentBatchConfig.transition = prevTransition;
}
}

function mountTransition(): [(() => void) => void, boolean] {
Expand Down
37 changes: 10 additions & 27 deletions packages/react-reconciler/src/ReactFiberHooks.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,6 @@ import {
markWorkInProgressReceivedUpdate,
checkIfWorkInProgressReceivedUpdate,
} from './ReactFiberBeginWork.old';
import {
UserBlockingPriority,
NormalPriority,
runWithPriority,
getCurrentPriorityLevel,
} from './SchedulerWithReactIntegration.old';
import {getIsHydrating} from './ReactFiberHydrationContext.old';
import {
makeClientId,
Expand Down Expand Up @@ -1711,38 +1705,27 @@ function rerenderDeferredValue<T>(value: T): T {
}

function startTransition(setPending, callback) {
const priorityLevel = getCurrentPriorityLevel();
const previousLanePriority = getCurrentUpdateLanePriority();
setCurrentUpdateLanePriority(
higherLanePriority(previousLanePriority, InputContinuousLanePriority),
);

runWithPriority(
priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel,
() => {
setPending(true);
},
);
setPending(true);

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

runWithPriority(
priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
() => {
const prevTransition = ReactCurrentBatchConfig.transition;
ReactCurrentBatchConfig.transition = 1;
try {
setPending(false);
callback();
} finally {
setCurrentUpdateLanePriority(previousLanePriority);
ReactCurrentBatchConfig.transition = prevTransition;
}
},
);
const prevTransition = ReactCurrentBatchConfig.transition;
ReactCurrentBatchConfig.transition = 1;
try {
setPending(false);
callback();
} finally {
setCurrentUpdateLanePriority(previousLanePriority);
ReactCurrentBatchConfig.transition = prevTransition;
}
}

function mountTransition(): [(() => void) => void, boolean] {
Expand Down
19 changes: 6 additions & 13 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import {
scheduleCallback,
cancelCallback,
getCurrentPriorityLevel,
runWithPriority,
shouldYield,
requestPaint,
now,
Expand Down Expand Up @@ -1124,7 +1123,7 @@ export function deferredUpdates<A>(fn: () => A): A {
const previousLanePriority = getCurrentUpdateLanePriority();
try {
setCurrentUpdateLanePriority(DefaultLanePriority);
return runWithPriority(NormalSchedulerPriority, fn);
return fn();
} finally {
setCurrentUpdateLanePriority(previousLanePriority);
}
Expand Down Expand Up @@ -1176,7 +1175,7 @@ export function batchedEventUpdates<A, R>(fn: A => R, a: A): R {
}

export function discreteUpdates<A, B, C, D, R>(
fn: (A, B, C) => R,
fn: (A, B, C, D) => R,
a: A,
b: B,
c: C,
Expand All @@ -1188,10 +1187,7 @@ export function discreteUpdates<A, B, C, D, R>(
const previousLanePriority = getCurrentUpdateLanePriority();
try {
setCurrentUpdateLanePriority(InputDiscreteLanePriority);
return runWithPriority(
UserBlockingSchedulerPriority,
fn.bind(null, a, b, c, d),
);
return fn(a, b, c, d);
} finally {
setCurrentUpdateLanePriority(previousLanePriority);
executionContext = prevExecutionContext;
Expand Down Expand Up @@ -1237,7 +1233,7 @@ export function flushSync<A, R>(fn: A => R, a: A): R {
try {
setCurrentUpdateLanePriority(SyncLanePriority);
if (fn) {
return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a));
return fn(a);
} else {
return (undefined: $FlowFixMe);
}
Expand All @@ -1257,7 +1253,7 @@ export function flushControlled(fn: () => mixed): void {
const previousLanePriority = getCurrentUpdateLanePriority();
try {
setCurrentUpdateLanePriority(SyncLanePriority);
runWithPriority(ImmediateSchedulerPriority, fn);
fn();
} finally {
setCurrentUpdateLanePriority(previousLanePriority);

Expand Down Expand Up @@ -1753,10 +1749,7 @@ function commitRoot(root) {
const previousUpdateLanePriority = getCurrentUpdateLanePriority();
try {
setCurrentUpdateLanePriority(SyncLanePriority);
runWithPriority(
ImmediateSchedulerPriority,
commitRootImpl.bind(null, root, previousUpdateLanePriority),
);
commitRootImpl(root, previousUpdateLanePriority);
} finally {
setCurrentUpdateLanePriority(previousUpdateLanePriority);
}
Expand Down
19 changes: 6 additions & 13 deletions packages/react-reconciler/src/ReactFiberWorkLoop.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import {
scheduleCallback,
cancelCallback,
getCurrentPriorityLevel,
runWithPriority,
shouldYield,
requestPaint,
now,
Expand Down Expand Up @@ -1124,7 +1123,7 @@ export function deferredUpdates<A>(fn: () => A): A {
const previousLanePriority = getCurrentUpdateLanePriority();
try {
setCurrentUpdateLanePriority(DefaultLanePriority);
return runWithPriority(NormalSchedulerPriority, fn);
return fn();
} finally {
setCurrentUpdateLanePriority(previousLanePriority);
}
Expand Down Expand Up @@ -1176,7 +1175,7 @@ export function batchedEventUpdates<A, R>(fn: A => R, a: A): R {
}

export function discreteUpdates<A, B, C, D, R>(
fn: (A, B, C) => R,
fn: (A, B, C, D) => R,
a: A,
b: B,
c: C,
Expand All @@ -1188,10 +1187,7 @@ export function discreteUpdates<A, B, C, D, R>(
const previousLanePriority = getCurrentUpdateLanePriority();
try {
setCurrentUpdateLanePriority(InputDiscreteLanePriority);
return runWithPriority(
UserBlockingSchedulerPriority,
fn.bind(null, a, b, c, d),
);
return fn(a, b, c, d);
} finally {
setCurrentUpdateLanePriority(previousLanePriority);
executionContext = prevExecutionContext;
Expand Down Expand Up @@ -1237,7 +1233,7 @@ export function flushSync<A, R>(fn: A => R, a: A): R {
try {
setCurrentUpdateLanePriority(SyncLanePriority);
if (fn) {
return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a));
return fn(a);
} else {
return (undefined: $FlowFixMe);
}
Expand All @@ -1257,7 +1253,7 @@ export function flushControlled(fn: () => mixed): void {
const previousLanePriority = getCurrentUpdateLanePriority();
try {
setCurrentUpdateLanePriority(SyncLanePriority);
runWithPriority(ImmediateSchedulerPriority, fn);
fn();
} finally {
setCurrentUpdateLanePriority(previousLanePriority);

Expand Down Expand Up @@ -1753,10 +1749,7 @@ function commitRoot(root) {
const previousUpdateLanePriority = getCurrentUpdateLanePriority();
try {
setCurrentUpdateLanePriority(SyncLanePriority);
runWithPriority(
ImmediateSchedulerPriority,
commitRootImpl.bind(null, root, previousUpdateLanePriority),
);
commitRootImpl(root, previousUpdateLanePriority);
} finally {
setCurrentUpdateLanePriority(previousUpdateLanePriority);
}
Expand Down
23 changes: 6 additions & 17 deletions packages/react-reconciler/src/SchedulerWithReactIntegration.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
import {scheduleMicrotask, supportsMicrotasks} from './ReactFiberHostConfig';

const {
unstable_runWithPriority: Scheduler_runWithPriority,
unstable_scheduleCallback: Scheduler_scheduleCallback,
unstable_cancelCallback: Scheduler_cancelCallback,
unstable_shouldYield: Scheduler_shouldYield,
Expand Down Expand Up @@ -123,14 +122,6 @@ function reactPriorityToSchedulerPriority(reactPriorityLevel) {
}
}

export function runWithPriority<T>(
reactPriorityLevel: ReactPriorityLevel,
fn: () => T,
): T {
const priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
return Scheduler_runWithPriority(priorityLevel, fn);
}

export function scheduleCallback(
reactPriorityLevel: ReactPriorityLevel,
callback: SchedulerCallback,
Expand Down Expand Up @@ -188,14 +179,12 @@ function flushSyncCallbackQueueImpl() {
const isSync = true;
const queue = syncQueue;
setCurrentUpdateLanePriority(SyncLanePriority);
runWithPriority(ImmediatePriority, () => {
for (; i < queue.length; i++) {
let callback = queue[i];
do {
callback = callback(isSync);
} while (callback !== null);
}
});
for (; i < queue.length; i++) {
let callback = queue[i];
do {
callback = callback(isSync);
} while (callback !== null);
}
syncQueue = null;
} catch (error) {
// If something throws, leave the remaining callbacks on the queue.
Expand Down
23 changes: 6 additions & 17 deletions packages/react-reconciler/src/SchedulerWithReactIntegration.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
import {scheduleMicrotask, supportsMicrotasks} from './ReactFiberHostConfig';

const {
unstable_runWithPriority: Scheduler_runWithPriority,
unstable_scheduleCallback: Scheduler_scheduleCallback,
unstable_cancelCallback: Scheduler_cancelCallback,
unstable_shouldYield: Scheduler_shouldYield,
Expand Down Expand Up @@ -123,14 +122,6 @@ function reactPriorityToSchedulerPriority(reactPriorityLevel) {
}
}

export function runWithPriority<T>(
reactPriorityLevel: ReactPriorityLevel,
fn: () => T,
): T {
const priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
return Scheduler_runWithPriority(priorityLevel, fn);
}

export function scheduleCallback(
reactPriorityLevel: ReactPriorityLevel,
callback: SchedulerCallback,
Expand Down Expand Up @@ -188,14 +179,12 @@ function flushSyncCallbackQueueImpl() {
const isSync = true;
const queue = syncQueue;
setCurrentUpdateLanePriority(SyncLanePriority);
runWithPriority(ImmediatePriority, () => {
for (; i < queue.length; i++) {
let callback = queue[i];
do {
callback = callback(isSync);
} while (callback !== null);
}
});
for (; i < queue.length; i++) {
let callback = queue[i];
do {
callback = callback(isSync);
} while (callback !== null);
}
syncQueue = null;
} catch (error) {
// If something throws, leave the remaining callbacks on the queue.
Expand Down
Loading

0 comments on commit 41e62e7

Please sign in to comment.