diff --git a/packages/react-dom/src/events/ReactDOMEventListener.js b/packages/react-dom/src/events/ReactDOMEventListener.js index e456f88c1e505..28dc3a8c713c7 100644 --- a/packages/react-dom/src/events/ReactDOMEventListener.js +++ b/packages/react-dom/src/events/ReactDOMEventListener.js @@ -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, @@ -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; @@ -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); } diff --git a/packages/react-reconciler/src/ReactFiberHooks.new.js b/packages/react-reconciler/src/ReactFiberHooks.new.js index 80fb17d78a670..9eb089d07d7a5 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.new.js +++ b/packages/react-reconciler/src/ReactFiberHooks.new.js @@ -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, @@ -1711,38 +1705,27 @@ function rerenderDeferredValue(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] { diff --git a/packages/react-reconciler/src/ReactFiberHooks.old.js b/packages/react-reconciler/src/ReactFiberHooks.old.js index 4436ce16707d0..b51d2020a8fad 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.old.js +++ b/packages/react-reconciler/src/ReactFiberHooks.old.js @@ -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, @@ -1711,38 +1705,27 @@ function rerenderDeferredValue(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] { diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js index f593cc8f8628a..65dc3f59181fc 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js @@ -41,7 +41,6 @@ import { scheduleCallback, cancelCallback, getCurrentPriorityLevel, - runWithPriority, shouldYield, requestPaint, now, @@ -1124,7 +1123,7 @@ export function deferredUpdates(fn: () => A): A { const previousLanePriority = getCurrentUpdateLanePriority(); try { setCurrentUpdateLanePriority(DefaultLanePriority); - return runWithPriority(NormalSchedulerPriority, fn); + return fn(); } finally { setCurrentUpdateLanePriority(previousLanePriority); } @@ -1176,7 +1175,7 @@ export function batchedEventUpdates(fn: A => R, a: A): R { } export function discreteUpdates( - fn: (A, B, C) => R, + fn: (A, B, C, D) => R, a: A, b: B, c: C, @@ -1188,10 +1187,7 @@ export function discreteUpdates( 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; @@ -1237,7 +1233,7 @@ export function flushSync(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); } @@ -1257,7 +1253,7 @@ export function flushControlled(fn: () => mixed): void { const previousLanePriority = getCurrentUpdateLanePriority(); try { setCurrentUpdateLanePriority(SyncLanePriority); - runWithPriority(ImmediateSchedulerPriority, fn); + fn(); } finally { setCurrentUpdateLanePriority(previousLanePriority); @@ -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); } diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js index 78849f9654877..a265ec896b774 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js @@ -41,7 +41,6 @@ import { scheduleCallback, cancelCallback, getCurrentPriorityLevel, - runWithPriority, shouldYield, requestPaint, now, @@ -1124,7 +1123,7 @@ export function deferredUpdates(fn: () => A): A { const previousLanePriority = getCurrentUpdateLanePriority(); try { setCurrentUpdateLanePriority(DefaultLanePriority); - return runWithPriority(NormalSchedulerPriority, fn); + return fn(); } finally { setCurrentUpdateLanePriority(previousLanePriority); } @@ -1176,7 +1175,7 @@ export function batchedEventUpdates(fn: A => R, a: A): R { } export function discreteUpdates( - fn: (A, B, C) => R, + fn: (A, B, C, D) => R, a: A, b: B, c: C, @@ -1188,10 +1187,7 @@ export function discreteUpdates( 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; @@ -1237,7 +1233,7 @@ export function flushSync(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); } @@ -1257,7 +1253,7 @@ export function flushControlled(fn: () => mixed): void { const previousLanePriority = getCurrentUpdateLanePriority(); try { setCurrentUpdateLanePriority(SyncLanePriority); - runWithPriority(ImmediateSchedulerPriority, fn); + fn(); } finally { setCurrentUpdateLanePriority(previousLanePriority); @@ -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); } diff --git a/packages/react-reconciler/src/SchedulerWithReactIntegration.new.js b/packages/react-reconciler/src/SchedulerWithReactIntegration.new.js index 4813dfc907f75..cd8cb58c6cedc 100644 --- a/packages/react-reconciler/src/SchedulerWithReactIntegration.new.js +++ b/packages/react-reconciler/src/SchedulerWithReactIntegration.new.js @@ -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, @@ -123,14 +122,6 @@ function reactPriorityToSchedulerPriority(reactPriorityLevel) { } } -export function runWithPriority( - reactPriorityLevel: ReactPriorityLevel, - fn: () => T, -): T { - const priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel); - return Scheduler_runWithPriority(priorityLevel, fn); -} - export function scheduleCallback( reactPriorityLevel: ReactPriorityLevel, callback: SchedulerCallback, @@ -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. diff --git a/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js b/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js index 1d1d8fb946abf..738ef2ea1afb7 100644 --- a/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js +++ b/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js @@ -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, @@ -123,14 +122,6 @@ function reactPriorityToSchedulerPriority(reactPriorityLevel) { } } -export function runWithPriority( - reactPriorityLevel: ReactPriorityLevel, - fn: () => T, -): T { - const priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel); - return Scheduler_runWithPriority(priorityLevel, fn); -} - export function scheduleCallback( reactPriorityLevel: ReactPriorityLevel, callback: SchedulerCallback, @@ -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. diff --git a/packages/react-reconciler/src/__tests__/ReactSchedulerIntegration-test.js b/packages/react-reconciler/src/__tests__/ReactSchedulerIntegration-test.js index 93ea812fb8175..bc05d1ab13d0b 100644 --- a/packages/react-reconciler/src/__tests__/ReactSchedulerIntegration-test.js +++ b/packages/react-reconciler/src/__tests__/ReactSchedulerIntegration-test.js @@ -68,17 +68,6 @@ describe('ReactSchedulerIntegration', () => { ); } - it('flush sync has correct priority', () => { - function ReadPriority() { - Scheduler.unstable_yieldValue( - 'Priority: ' + getCurrentPriorityAsString(), - ); - return null; - } - ReactNoop.flushSync(() => ReactNoop.render()); - expect(Scheduler).toHaveYielded(['Priority: Immediate']); - }); - // TODO: Figure out what to do with these tests. I don't think most of them // make sense once we decouple Scheduler from React. Perhaps need similar // tests for React DOM. @@ -139,27 +128,6 @@ describe('ReactSchedulerIntegration', () => { ]); }); - it('layout effects have immediate priority', () => { - const {useLayoutEffect} = React; - function ReadPriority() { - Scheduler.unstable_yieldValue( - 'Render priority: ' + getCurrentPriorityAsString(), - ); - useLayoutEffect(() => { - Scheduler.unstable_yieldValue( - 'Layout priority: ' + getCurrentPriorityAsString(), - ); - }); - return null; - } - - ReactNoop.render(); - expect(Scheduler).toFlushAndYield([ - 'Render priority: Normal', - 'Layout priority: Immediate', - ]); - }); - it('passive effects are called before Normal-pri scheduled in layout effects', async () => { const {useEffect, useLayoutEffect} = React; function Effects({step}) {