From e89d74ee679bafe09213ef66394dd530d2168787 Mon Sep 17 00:00:00 2001 From: Rick Hanlon Date: Mon, 8 Mar 2021 09:16:30 -0700 Subject: [PATCH] Remove decoupleUpdatePriorityFromScheduler --- .../src/events/ReactDOMEventListener.js | 26 +-- .../src/ReactFiberHooks.new.js | 86 +++----- .../src/ReactFiberHooks.old.js | 86 +++----- .../src/ReactFiberWorkLoop.new.js | 196 +++++------------- .../src/ReactFiberWorkLoop.old.js | 196 +++++------------- .../src/SchedulerWithReactIntegration.new.js | 82 +++----- .../src/SchedulerWithReactIntegration.old.js | 82 +++----- .../ReactDOMTracing-test.internal.js | 2 - packages/shared/ReactFeatureFlags.js | 3 - .../forks/ReactFeatureFlags.native-fb.js | 1 - .../forks/ReactFeatureFlags.native-oss.js | 1 - .../forks/ReactFeatureFlags.test-renderer.js | 1 - .../ReactFeatureFlags.test-renderer.native.js | 1 - .../ReactFeatureFlags.test-renderer.www.js | 1 - .../shared/forks/ReactFeatureFlags.testing.js | 1 - .../forks/ReactFeatureFlags.testing.www.js | 1 - .../forks/ReactFeatureFlags.www-dynamic.js | 1 - .../shared/forks/ReactFeatureFlags.www.js | 1 - 18 files changed, 226 insertions(+), 542 deletions(-) diff --git a/packages/react-dom/src/events/ReactDOMEventListener.js b/packages/react-dom/src/events/ReactDOMEventListener.js index dd7fda27f0a93..e456f88c1e505 100644 --- a/packages/react-dom/src/events/ReactDOMEventListener.js +++ b/packages/react-dom/src/events/ReactDOMEventListener.js @@ -40,7 +40,6 @@ import {getClosestInstanceFromNode} from '../client/ReactDOMComponentTree'; import { enableLegacyFBSupport, - decoupleUpdatePriorityFromScheduler, enableNewReconciler, } from 'shared/ReactFeatureFlags'; import {dispatchEventForPluginEventSystem} from './DOMPluginEventSystem'; @@ -177,25 +176,10 @@ function dispatchContinuousEvent( container, nativeEvent, ) { - if (decoupleUpdatePriorityFromScheduler) { - 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, - ), - ); - } finally { - setCurrentUpdateLanePriority(previousPriority); - } - } else { + const previousPriority = getCurrentUpdateLanePriority(); + try { + // TODO: Double wrapping is necessary while we decouple Scheduler priority. + setCurrentUpdateLanePriority(InputContinuousLanePriority); runWithPriority( UserBlockingPriority, dispatchEvent.bind( @@ -206,6 +190,8 @@ function dispatchContinuousEvent( nativeEvent, ), ); + } finally { + setCurrentUpdateLanePriority(previousPriority); } } diff --git a/packages/react-reconciler/src/ReactFiberHooks.new.js b/packages/react-reconciler/src/ReactFiberHooks.new.js index e7e5c3128beac..80fb17d78a670 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.new.js +++ b/packages/react-reconciler/src/ReactFiberHooks.new.js @@ -27,7 +27,6 @@ import { enableSchedulingProfiler, enableNewReconciler, enableCache, - decoupleUpdatePriorityFromScheduler, enableUseRefAccessWarning, enableStrictEffects, enableLazyContextPropagation, @@ -1713,66 +1712,37 @@ function rerenderDeferredValue(value: T): T { function startTransition(setPending, callback) { const priorityLevel = getCurrentPriorityLevel(); - if (decoupleUpdatePriorityFromScheduler) { - const previousLanePriority = getCurrentUpdateLanePriority(); - setCurrentUpdateLanePriority( - higherLanePriority(previousLanePriority, InputContinuousLanePriority), - ); + const previousLanePriority = getCurrentUpdateLanePriority(); + setCurrentUpdateLanePriority( + higherLanePriority(previousLanePriority, InputContinuousLanePriority), + ); - runWithPriority( - priorityLevel < UserBlockingPriority - ? UserBlockingPriority - : priorityLevel, - () => { - setPending(true); - }, - ); + runWithPriority( + priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel, + () => { + 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); + // 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 { - if (decoupleUpdatePriorityFromScheduler) { - setCurrentUpdateLanePriority(previousLanePriority); - } - ReactCurrentBatchConfig.transition = prevTransition; - } - }, - ); - } else { - runWithPriority( - priorityLevel < UserBlockingPriority - ? UserBlockingPriority - : priorityLevel, - () => { - setPending(true); - }, - ); - - runWithPriority( - priorityLevel > NormalPriority ? NormalPriority : priorityLevel, - () => { - const prevTransition = ReactCurrentBatchConfig.transition; - ReactCurrentBatchConfig.transition = 1; - try { - setPending(false); - callback(); - } finally { - ReactCurrentBatchConfig.transition = prevTransition; - } - }, - ); - } + runWithPriority( + priorityLevel > NormalPriority ? NormalPriority : priorityLevel, + () => { + 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 55dca75656c35..4436ce16707d0 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.old.js +++ b/packages/react-reconciler/src/ReactFiberHooks.old.js @@ -27,7 +27,6 @@ import { enableSchedulingProfiler, enableNewReconciler, enableCache, - decoupleUpdatePriorityFromScheduler, enableUseRefAccessWarning, enableStrictEffects, enableLazyContextPropagation, @@ -1713,66 +1712,37 @@ function rerenderDeferredValue(value: T): T { function startTransition(setPending, callback) { const priorityLevel = getCurrentPriorityLevel(); - if (decoupleUpdatePriorityFromScheduler) { - const previousLanePriority = getCurrentUpdateLanePriority(); - setCurrentUpdateLanePriority( - higherLanePriority(previousLanePriority, InputContinuousLanePriority), - ); + const previousLanePriority = getCurrentUpdateLanePriority(); + setCurrentUpdateLanePriority( + higherLanePriority(previousLanePriority, InputContinuousLanePriority), + ); - runWithPriority( - priorityLevel < UserBlockingPriority - ? UserBlockingPriority - : priorityLevel, - () => { - setPending(true); - }, - ); + runWithPriority( + priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel, + () => { + 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); + // 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 { - if (decoupleUpdatePriorityFromScheduler) { - setCurrentUpdateLanePriority(previousLanePriority); - } - ReactCurrentBatchConfig.transition = prevTransition; - } - }, - ); - } else { - runWithPriority( - priorityLevel < UserBlockingPriority - ? UserBlockingPriority - : priorityLevel, - () => { - setPending(true); - }, - ); - - runWithPriority( - priorityLevel > NormalPriority ? NormalPriority : priorityLevel, - () => { - const prevTransition = ReactCurrentBatchConfig.transition; - ReactCurrentBatchConfig.transition = 1; - try { - setPending(false); - callback(); - } finally { - ReactCurrentBatchConfig.transition = prevTransition; - } - }, - ); - } + runWithPriority( + priorityLevel > NormalPriority ? NormalPriority : priorityLevel, + () => { + 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 0e4a3aad8d715..caf3bf5793370 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js @@ -28,7 +28,6 @@ import { enableSchedulerTracing, warnAboutUnmockedScheduler, deferRenderPhaseUpdateToNextBatch, - decoupleUpdatePriorityFromScheduler, enableDebugTracing, enableSchedulingProfiler, disableSchedulerTimeoutInWorkLoop, @@ -455,10 +454,7 @@ export function requestUpdateLane(fiber: Fiber): Lane { schedulerPriority === UserBlockingSchedulerPriority ) { lane = findUpdateLane(InputDiscreteLanePriority); - } else if ( - decoupleUpdatePriorityFromScheduler && - getCurrentUpdateLanePriority() !== NoLanePriority - ) { + } else if (getCurrentUpdateLanePriority() !== NoLanePriority) { const currentLanePriority = getCurrentUpdateLanePriority(); lane = findUpdateLane(currentLanePriority); } else { @@ -567,10 +563,6 @@ export function scheduleUpdateOnFiber( } } - // TODO: requestUpdateLanePriority also reads the priority. Pass the - // priority as an argument to that function and this one. - const priorityLevel = getCurrentPriorityLevel(); - if (lane === SyncLane) { if ( // Check if we're inside unbatchedUpdates @@ -598,7 +590,7 @@ export function scheduleUpdateOnFiber( flushSyncCallbackQueue(); } } - } else if (decoupleUpdatePriorityFromScheduler) { + } else { const updateLanePriority = getCurrentUpdateLanePriority(); // Schedule a discrete update but only if it's not Sync. @@ -619,26 +611,6 @@ export function scheduleUpdateOnFiber( // Schedule other updates after in case the callback is sync. ensureRootIsScheduled(root, eventTime); schedulePendingInteractions(root, lane); - } else { - // Schedule a discrete update but only if it's not Sync. - if ( - (executionContext & DiscreteEventContext) !== NoContext && - // Only updates at user-blocking priority or greater are considered - // discrete, even inside a discrete event. - (priorityLevel === UserBlockingSchedulerPriority || - priorityLevel === ImmediateSchedulerPriority) - ) { - // This is the result of a discrete event. Track the lowest priority - // discrete update per root so we can flush them early, if needed. - if (rootsWithPendingDiscreteUpdates === null) { - rootsWithPendingDiscreteUpdates = new Set([root]); - } else { - rootsWithPendingDiscreteUpdates.add(root); - } - } - // Schedule other updates after in case the callback is sync. - ensureRootIsScheduled(root, eventTime); - schedulePendingInteractions(root, lane); } return root; @@ -1150,16 +1122,12 @@ export function flushDiscreteUpdates() { } export function deferredUpdates(fn: () => A): A { - if (decoupleUpdatePriorityFromScheduler) { - const previousLanePriority = getCurrentUpdateLanePriority(); - try { - setCurrentUpdateLanePriority(DefaultLanePriority); - return runWithPriority(NormalSchedulerPriority, fn); - } finally { - setCurrentUpdateLanePriority(previousLanePriority); - } - } else { + const previousLanePriority = getCurrentUpdateLanePriority(); + try { + setCurrentUpdateLanePriority(DefaultLanePriority); return runWithPriority(NormalSchedulerPriority, fn); + } finally { + setCurrentUpdateLanePriority(previousLanePriority); } } @@ -1218,36 +1186,20 @@ export function discreteUpdates( const prevExecutionContext = executionContext; executionContext |= DiscreteEventContext; - if (decoupleUpdatePriorityFromScheduler) { - const previousLanePriority = getCurrentUpdateLanePriority(); - try { - setCurrentUpdateLanePriority(InputDiscreteLanePriority); - return runWithPriority( - UserBlockingSchedulerPriority, - fn.bind(null, a, b, c, d), - ); - } finally { - setCurrentUpdateLanePriority(previousLanePriority); - executionContext = prevExecutionContext; - if (executionContext === NoContext) { - // Flush the immediate callbacks that were scheduled during this batch - resetRenderTimer(); - flushSyncCallbackQueue(); - } - } - } else { - try { - return runWithPriority( - UserBlockingSchedulerPriority, - fn.bind(null, a, b, c, d), - ); - } finally { - executionContext = prevExecutionContext; - if (executionContext === NoContext) { - // Flush the immediate callbacks that were scheduled during this batch - resetRenderTimer(); - flushSyncCallbackQueue(); - } + const previousLanePriority = getCurrentUpdateLanePriority(); + try { + setCurrentUpdateLanePriority(InputDiscreteLanePriority); + return runWithPriority( + UserBlockingSchedulerPriority, + fn.bind(null, a, b, c, d), + ); + } finally { + setCurrentUpdateLanePriority(previousLanePriority); + executionContext = prevExecutionContext; + if (executionContext === NoContext) { + // Flush the immediate callbacks that were scheduled during this batch + resetRenderTimer(); + flushSyncCallbackQueue(); } } } @@ -1282,68 +1234,39 @@ export function flushSync(fn: A => R, a: A): R { } executionContext |= BatchedContext; - if (decoupleUpdatePriorityFromScheduler) { - const previousLanePriority = getCurrentUpdateLanePriority(); - try { - setCurrentUpdateLanePriority(SyncLanePriority); - if (fn) { - return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a)); - } else { - return (undefined: $FlowFixMe); - } - } finally { - setCurrentUpdateLanePriority(previousLanePriority); - executionContext = prevExecutionContext; - // Flush the immediate callbacks that were scheduled during this batch. - // Note that this will happen even if batchedUpdates is higher up - // the stack. - flushSyncCallbackQueue(); - } - } else { - try { - if (fn) { - return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a)); - } else { - return (undefined: $FlowFixMe); - } - } finally { - executionContext = prevExecutionContext; - // Flush the immediate callbacks that were scheduled during this batch. - // Note that this will happen even if batchedUpdates is higher up - // the stack. - flushSyncCallbackQueue(); + const previousLanePriority = getCurrentUpdateLanePriority(); + try { + setCurrentUpdateLanePriority(SyncLanePriority); + if (fn) { + return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a)); + } else { + return (undefined: $FlowFixMe); } + } finally { + setCurrentUpdateLanePriority(previousLanePriority); + executionContext = prevExecutionContext; + // Flush the immediate callbacks that were scheduled during this batch. + // Note that this will happen even if batchedUpdates is higher up + // the stack. + flushSyncCallbackQueue(); } } export function flushControlled(fn: () => mixed): void { const prevExecutionContext = executionContext; executionContext |= BatchedContext; - if (decoupleUpdatePriorityFromScheduler) { - const previousLanePriority = getCurrentUpdateLanePriority(); - try { - setCurrentUpdateLanePriority(SyncLanePriority); - runWithPriority(ImmediateSchedulerPriority, fn); - } finally { - setCurrentUpdateLanePriority(previousLanePriority); + const previousLanePriority = getCurrentUpdateLanePriority(); + try { + setCurrentUpdateLanePriority(SyncLanePriority); + runWithPriority(ImmediateSchedulerPriority, fn); + } finally { + setCurrentUpdateLanePriority(previousLanePriority); - executionContext = prevExecutionContext; - if (executionContext === NoContext) { - // Flush the immediate callbacks that were scheduled during this batch - resetRenderTimer(); - flushSyncCallbackQueue(); - } - } - } else { - try { - runWithPriority(ImmediateSchedulerPriority, fn); - } finally { - executionContext = prevExecutionContext; - if (executionContext === NoContext) { - // Flush the immediate callbacks that were scheduled during this batch - resetRenderTimer(); - flushSyncCallbackQueue(); - } + executionContext = prevExecutionContext; + if (executionContext === NoContext) { + // Flush the immediate callbacks that were scheduled during this batch + resetRenderTimer(); + flushSyncCallbackQueue(); } } } @@ -1954,11 +1877,8 @@ function commitRootImpl(root, renderPriorityLevel) { NoFlags; if (subtreeHasEffects || rootHasEffect) { - let previousLanePriority; - if (decoupleUpdatePriorityFromScheduler) { - previousLanePriority = getCurrentUpdateLanePriority(); - setCurrentUpdateLanePriority(SyncLanePriority); - } + const previousLanePriority = getCurrentUpdateLanePriority(); + setCurrentUpdateLanePriority(SyncLanePriority); const prevExecutionContext = executionContext; executionContext |= CommitContext; @@ -2040,7 +1960,7 @@ function commitRootImpl(root, renderPriorityLevel) { } executionContext = prevExecutionContext; - if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { + if (previousLanePriority != null) { // Reset the priority to the previous non-sync value. setCurrentUpdateLanePriority(previousLanePriority); } @@ -2183,18 +2103,14 @@ export function flushPassiveEffects(): boolean { ? NormalSchedulerPriority : pendingPassiveEffectsRenderPriority; pendingPassiveEffectsRenderPriority = NoSchedulerPriority; - if (decoupleUpdatePriorityFromScheduler) { - const previousLanePriority = getCurrentUpdateLanePriority(); - try { - setCurrentUpdateLanePriority( - schedulerPriorityToLanePriority(priorityLevel), - ); - return runWithPriority(priorityLevel, flushPassiveEffectsImpl); - } finally { - setCurrentUpdateLanePriority(previousLanePriority); - } - } else { + const previousLanePriority = getCurrentUpdateLanePriority(); + try { + setCurrentUpdateLanePriority( + schedulerPriorityToLanePriority(priorityLevel), + ); return runWithPriority(priorityLevel, flushPassiveEffectsImpl); + } finally { + setCurrentUpdateLanePriority(previousLanePriority); } } return false; diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js index 77bd914eaa5fc..4365b2b83ac43 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js @@ -28,7 +28,6 @@ import { enableSchedulerTracing, warnAboutUnmockedScheduler, deferRenderPhaseUpdateToNextBatch, - decoupleUpdatePriorityFromScheduler, enableDebugTracing, enableSchedulingProfiler, disableSchedulerTimeoutInWorkLoop, @@ -455,10 +454,7 @@ export function requestUpdateLane(fiber: Fiber): Lane { schedulerPriority === UserBlockingSchedulerPriority ) { lane = findUpdateLane(InputDiscreteLanePriority); - } else if ( - decoupleUpdatePriorityFromScheduler && - getCurrentUpdateLanePriority() !== NoLanePriority - ) { + } else if (getCurrentUpdateLanePriority() !== NoLanePriority) { const currentLanePriority = getCurrentUpdateLanePriority(); lane = findUpdateLane(currentLanePriority); } else { @@ -567,10 +563,6 @@ export function scheduleUpdateOnFiber( } } - // TODO: requestUpdateLanePriority also reads the priority. Pass the - // priority as an argument to that function and this one. - const priorityLevel = getCurrentPriorityLevel(); - if (lane === SyncLane) { if ( // Check if we're inside unbatchedUpdates @@ -598,7 +590,7 @@ export function scheduleUpdateOnFiber( flushSyncCallbackQueue(); } } - } else if (decoupleUpdatePriorityFromScheduler) { + } else { const updateLanePriority = getCurrentUpdateLanePriority(); // Schedule a discrete update but only if it's not Sync. @@ -619,26 +611,6 @@ export function scheduleUpdateOnFiber( // Schedule other updates after in case the callback is sync. ensureRootIsScheduled(root, eventTime); schedulePendingInteractions(root, lane); - } else { - // Schedule a discrete update but only if it's not Sync. - if ( - (executionContext & DiscreteEventContext) !== NoContext && - // Only updates at user-blocking priority or greater are considered - // discrete, even inside a discrete event. - (priorityLevel === UserBlockingSchedulerPriority || - priorityLevel === ImmediateSchedulerPriority) - ) { - // This is the result of a discrete event. Track the lowest priority - // discrete update per root so we can flush them early, if needed. - if (rootsWithPendingDiscreteUpdates === null) { - rootsWithPendingDiscreteUpdates = new Set([root]); - } else { - rootsWithPendingDiscreteUpdates.add(root); - } - } - // Schedule other updates after in case the callback is sync. - ensureRootIsScheduled(root, eventTime); - schedulePendingInteractions(root, lane); } return root; @@ -1150,16 +1122,12 @@ export function flushDiscreteUpdates() { } export function deferredUpdates(fn: () => A): A { - if (decoupleUpdatePriorityFromScheduler) { - const previousLanePriority = getCurrentUpdateLanePriority(); - try { - setCurrentUpdateLanePriority(DefaultLanePriority); - return runWithPriority(NormalSchedulerPriority, fn); - } finally { - setCurrentUpdateLanePriority(previousLanePriority); - } - } else { + const previousLanePriority = getCurrentUpdateLanePriority(); + try { + setCurrentUpdateLanePriority(DefaultLanePriority); return runWithPriority(NormalSchedulerPriority, fn); + } finally { + setCurrentUpdateLanePriority(previousLanePriority); } } @@ -1218,36 +1186,20 @@ export function discreteUpdates( const prevExecutionContext = executionContext; executionContext |= DiscreteEventContext; - if (decoupleUpdatePriorityFromScheduler) { - const previousLanePriority = getCurrentUpdateLanePriority(); - try { - setCurrentUpdateLanePriority(InputDiscreteLanePriority); - return runWithPriority( - UserBlockingSchedulerPriority, - fn.bind(null, a, b, c, d), - ); - } finally { - setCurrentUpdateLanePriority(previousLanePriority); - executionContext = prevExecutionContext; - if (executionContext === NoContext) { - // Flush the immediate callbacks that were scheduled during this batch - resetRenderTimer(); - flushSyncCallbackQueue(); - } - } - } else { - try { - return runWithPriority( - UserBlockingSchedulerPriority, - fn.bind(null, a, b, c, d), - ); - } finally { - executionContext = prevExecutionContext; - if (executionContext === NoContext) { - // Flush the immediate callbacks that were scheduled during this batch - resetRenderTimer(); - flushSyncCallbackQueue(); - } + const previousLanePriority = getCurrentUpdateLanePriority(); + try { + setCurrentUpdateLanePriority(InputDiscreteLanePriority); + return runWithPriority( + UserBlockingSchedulerPriority, + fn.bind(null, a, b, c, d), + ); + } finally { + setCurrentUpdateLanePriority(previousLanePriority); + executionContext = prevExecutionContext; + if (executionContext === NoContext) { + // Flush the immediate callbacks that were scheduled during this batch + resetRenderTimer(); + flushSyncCallbackQueue(); } } } @@ -1282,68 +1234,39 @@ export function flushSync(fn: A => R, a: A): R { } executionContext |= BatchedContext; - if (decoupleUpdatePriorityFromScheduler) { - const previousLanePriority = getCurrentUpdateLanePriority(); - try { - setCurrentUpdateLanePriority(SyncLanePriority); - if (fn) { - return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a)); - } else { - return (undefined: $FlowFixMe); - } - } finally { - setCurrentUpdateLanePriority(previousLanePriority); - executionContext = prevExecutionContext; - // Flush the immediate callbacks that were scheduled during this batch. - // Note that this will happen even if batchedUpdates is higher up - // the stack. - flushSyncCallbackQueue(); - } - } else { - try { - if (fn) { - return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a)); - } else { - return (undefined: $FlowFixMe); - } - } finally { - executionContext = prevExecutionContext; - // Flush the immediate callbacks that were scheduled during this batch. - // Note that this will happen even if batchedUpdates is higher up - // the stack. - flushSyncCallbackQueue(); + const previousLanePriority = getCurrentUpdateLanePriority(); + try { + setCurrentUpdateLanePriority(SyncLanePriority); + if (fn) { + return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a)); + } else { + return (undefined: $FlowFixMe); } + } finally { + setCurrentUpdateLanePriority(previousLanePriority); + executionContext = prevExecutionContext; + // Flush the immediate callbacks that were scheduled during this batch. + // Note that this will happen even if batchedUpdates is higher up + // the stack. + flushSyncCallbackQueue(); } } export function flushControlled(fn: () => mixed): void { const prevExecutionContext = executionContext; executionContext |= BatchedContext; - if (decoupleUpdatePriorityFromScheduler) { - const previousLanePriority = getCurrentUpdateLanePriority(); - try { - setCurrentUpdateLanePriority(SyncLanePriority); - runWithPriority(ImmediateSchedulerPriority, fn); - } finally { - setCurrentUpdateLanePriority(previousLanePriority); + const previousLanePriority = getCurrentUpdateLanePriority(); + try { + setCurrentUpdateLanePriority(SyncLanePriority); + runWithPriority(ImmediateSchedulerPriority, fn); + } finally { + setCurrentUpdateLanePriority(previousLanePriority); - executionContext = prevExecutionContext; - if (executionContext === NoContext) { - // Flush the immediate callbacks that were scheduled during this batch - resetRenderTimer(); - flushSyncCallbackQueue(); - } - } - } else { - try { - runWithPriority(ImmediateSchedulerPriority, fn); - } finally { - executionContext = prevExecutionContext; - if (executionContext === NoContext) { - // Flush the immediate callbacks that were scheduled during this batch - resetRenderTimer(); - flushSyncCallbackQueue(); - } + executionContext = prevExecutionContext; + if (executionContext === NoContext) { + // Flush the immediate callbacks that were scheduled during this batch + resetRenderTimer(); + flushSyncCallbackQueue(); } } } @@ -1954,11 +1877,8 @@ function commitRootImpl(root, renderPriorityLevel) { NoFlags; if (subtreeHasEffects || rootHasEffect) { - let previousLanePriority; - if (decoupleUpdatePriorityFromScheduler) { - previousLanePriority = getCurrentUpdateLanePriority(); - setCurrentUpdateLanePriority(SyncLanePriority); - } + const previousLanePriority = getCurrentUpdateLanePriority(); + setCurrentUpdateLanePriority(SyncLanePriority); const prevExecutionContext = executionContext; executionContext |= CommitContext; @@ -2040,7 +1960,7 @@ function commitRootImpl(root, renderPriorityLevel) { } executionContext = prevExecutionContext; - if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { + if (previousLanePriority != null) { // Reset the priority to the previous non-sync value. setCurrentUpdateLanePriority(previousLanePriority); } @@ -2183,18 +2103,14 @@ export function flushPassiveEffects(): boolean { ? NormalSchedulerPriority : pendingPassiveEffectsRenderPriority; pendingPassiveEffectsRenderPriority = NoSchedulerPriority; - if (decoupleUpdatePriorityFromScheduler) { - const previousLanePriority = getCurrentUpdateLanePriority(); - try { - setCurrentUpdateLanePriority( - schedulerPriorityToLanePriority(priorityLevel), - ); - return runWithPriority(priorityLevel, flushPassiveEffectsImpl); - } finally { - setCurrentUpdateLanePriority(previousLanePriority); - } - } else { + const previousLanePriority = getCurrentUpdateLanePriority(); + try { + setCurrentUpdateLanePriority( + schedulerPriorityToLanePriority(priorityLevel), + ); return runWithPriority(priorityLevel, flushPassiveEffectsImpl); + } finally { + setCurrentUpdateLanePriority(previousLanePriority); } } return false; diff --git a/packages/react-reconciler/src/SchedulerWithReactIntegration.new.js b/packages/react-reconciler/src/SchedulerWithReactIntegration.new.js index 1c13e3a8fda90..4813dfc907f75 100644 --- a/packages/react-reconciler/src/SchedulerWithReactIntegration.new.js +++ b/packages/react-reconciler/src/SchedulerWithReactIntegration.new.js @@ -15,7 +15,6 @@ import * as Scheduler from 'scheduler'; import {__interactionsRef} from 'scheduler/tracing'; import { enableSchedulerTracing, - decoupleUpdatePriorityFromScheduler, enableSyncMicroTasks, } from 'shared/ReactFeatureFlags'; import invariant from 'shared/invariant'; @@ -184,63 +183,34 @@ function flushSyncCallbackQueueImpl() { // Prevent re-entrancy. isFlushingSyncQueue = true; let i = 0; - if (decoupleUpdatePriorityFromScheduler) { - const previousLanePriority = getCurrentUpdateLanePriority(); - try { - 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); - } - }); - syncQueue = null; - } catch (error) { - // If something throws, leave the remaining callbacks on the queue. - if (syncQueue !== null) { - syncQueue = syncQueue.slice(i + 1); + const previousLanePriority = getCurrentUpdateLanePriority(); + try { + 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); } - // Resume flushing in the next tick - Scheduler_scheduleCallback( - Scheduler_ImmediatePriority, - flushSyncCallbackQueue, - ); - throw error; - } finally { - setCurrentUpdateLanePriority(previousLanePriority); - isFlushingSyncQueue = false; - } - } else { - try { - const isSync = true; - const queue = syncQueue; - runWithPriority(ImmediatePriority, () => { - 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. - if (syncQueue !== null) { - syncQueue = syncQueue.slice(i + 1); - } - // Resume flushing in the next tick - Scheduler_scheduleCallback( - Scheduler_ImmediatePriority, - flushSyncCallbackQueue, - ); - throw error; - } finally { - isFlushingSyncQueue = false; + }); + syncQueue = null; + } catch (error) { + // If something throws, leave the remaining callbacks on the queue. + if (syncQueue !== null) { + syncQueue = syncQueue.slice(i + 1); } + // Resume flushing in the next tick + Scheduler_scheduleCallback( + Scheduler_ImmediatePriority, + flushSyncCallbackQueue, + ); + throw error; + } finally { + setCurrentUpdateLanePriority(previousLanePriority); + isFlushingSyncQueue = false; } } } diff --git a/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js b/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js index 5c4451499ca5b..1d1d8fb946abf 100644 --- a/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js +++ b/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js @@ -15,7 +15,6 @@ import * as Scheduler from 'scheduler'; import {__interactionsRef} from 'scheduler/tracing'; import { enableSchedulerTracing, - decoupleUpdatePriorityFromScheduler, enableSyncMicroTasks, } from 'shared/ReactFeatureFlags'; import invariant from 'shared/invariant'; @@ -184,63 +183,34 @@ function flushSyncCallbackQueueImpl() { // Prevent re-entrancy. isFlushingSyncQueue = true; let i = 0; - if (decoupleUpdatePriorityFromScheduler) { - const previousLanePriority = getCurrentUpdateLanePriority(); - try { - 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); - } - }); - syncQueue = null; - } catch (error) { - // If something throws, leave the remaining callbacks on the queue. - if (syncQueue !== null) { - syncQueue = syncQueue.slice(i + 1); + const previousLanePriority = getCurrentUpdateLanePriority(); + try { + 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); } - // Resume flushing in the next tick - Scheduler_scheduleCallback( - Scheduler_ImmediatePriority, - flushSyncCallbackQueue, - ); - throw error; - } finally { - setCurrentUpdateLanePriority(previousLanePriority); - isFlushingSyncQueue = false; - } - } else { - try { - const isSync = true; - const queue = syncQueue; - runWithPriority(ImmediatePriority, () => { - 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. - if (syncQueue !== null) { - syncQueue = syncQueue.slice(i + 1); - } - // Resume flushing in the next tick - Scheduler_scheduleCallback( - Scheduler_ImmediatePriority, - flushSyncCallbackQueue, - ); - throw error; - } finally { - isFlushingSyncQueue = false; + }); + syncQueue = null; + } catch (error) { + // If something throws, leave the remaining callbacks on the queue. + if (syncQueue !== null) { + syncQueue = syncQueue.slice(i + 1); } + // Resume flushing in the next tick + Scheduler_scheduleCallback( + Scheduler_ImmediatePriority, + flushSyncCallbackQueue, + ); + throw error; + } finally { + setCurrentUpdateLanePriority(previousLanePriority); + isFlushingSyncQueue = false; } } } diff --git a/packages/react/src/__tests__/ReactDOMTracing-test.internal.js b/packages/react/src/__tests__/ReactDOMTracing-test.internal.js index e2a76513f721c..114b0cfffee53 100644 --- a/packages/react/src/__tests__/ReactDOMTracing-test.internal.js +++ b/packages/react/src/__tests__/ReactDOMTracing-test.internal.js @@ -428,7 +428,6 @@ describe('ReactDOMTracing', () => { }); // @gate experimental - // @gate enableNativeEventPriorityInference it('should properly trace interactions when there is work of interleaved priorities', () => { const Child = () => { Scheduler.unstable_yieldValue('Child'); @@ -550,7 +549,6 @@ describe('ReactDOMTracing', () => { }); // @gate experimental - // @gate enableNativeEventPriorityInference it('should properly trace interactions through a multi-pass SuspenseList render', () => { const SuspenseList = React.SuspenseList; const Suspense = React.Suspense; diff --git a/packages/shared/ReactFeatureFlags.js b/packages/shared/ReactFeatureFlags.js index 484717599557a..0d83efe103329 100644 --- a/packages/shared/ReactFeatureFlags.js +++ b/packages/shared/ReactFeatureFlags.js @@ -142,9 +142,6 @@ export const enableLegacyFBSupport = false; // new behavior. export const deferRenderPhaseUpdateToNextBatch = true; -// Replacement for runWithPriority in React internals. -export const decoupleUpdatePriorityFromScheduler = false; - export const enableDiscreteEventFlushingChange = false; export const enableUseRefAccessWarning = false; diff --git a/packages/shared/forks/ReactFeatureFlags.native-fb.js b/packages/shared/forks/ReactFeatureFlags.native-fb.js index b664dc00632a5..b0dad1851fac6 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-fb.js +++ b/packages/shared/forks/ReactFeatureFlags.native-fb.js @@ -49,7 +49,6 @@ export const skipUnmountedBoundaries = false; export const enableNewReconciler = false; export const deferRenderPhaseUpdateToNextBatch = true; -export const decoupleUpdatePriorityFromScheduler = false; export const enableDiscreteEventFlushingChange = false; export const enableStrictEffects = false; diff --git a/packages/shared/forks/ReactFeatureFlags.native-oss.js b/packages/shared/forks/ReactFeatureFlags.native-oss.js index f5d44fff13083..7a34c7623cfdb 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-oss.js +++ b/packages/shared/forks/ReactFeatureFlags.native-oss.js @@ -48,7 +48,6 @@ export const skipUnmountedBoundaries = false; export const enableNewReconciler = false; export const deferRenderPhaseUpdateToNextBatch = true; -export const decoupleUpdatePriorityFromScheduler = false; export const enableDiscreteEventFlushingChange = false; export const enableStrictEffects = false; diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.js index e05226fd5d019..adb63e0a8df5c 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.js @@ -48,7 +48,6 @@ export const skipUnmountedBoundaries = false; export const enableNewReconciler = false; export const deferRenderPhaseUpdateToNextBatch = true; -export const decoupleUpdatePriorityFromScheduler = false; export const enableDiscreteEventFlushingChange = false; export const enableStrictEffects = false; diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js index 41a368f659ec8..5c18737ebec6a 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.native.js @@ -48,7 +48,6 @@ export const skipUnmountedBoundaries = false; export const enableNewReconciler = false; export const deferRenderPhaseUpdateToNextBatch = true; -export const decoupleUpdatePriorityFromScheduler = false; export const enableDiscreteEventFlushingChange = false; export const enableStrictEffects = false; diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js index 577e77f18df90..9ef9ee181b607 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js @@ -48,7 +48,6 @@ export const skipUnmountedBoundaries = false; export const enableNewReconciler = false; export const deferRenderPhaseUpdateToNextBatch = true; -export const decoupleUpdatePriorityFromScheduler = false; export const enableDiscreteEventFlushingChange = false; export const enableStrictEffects = true; diff --git a/packages/shared/forks/ReactFeatureFlags.testing.js b/packages/shared/forks/ReactFeatureFlags.testing.js index 0d7c78e39e294..b3240c62dad37 100644 --- a/packages/shared/forks/ReactFeatureFlags.testing.js +++ b/packages/shared/forks/ReactFeatureFlags.testing.js @@ -48,7 +48,6 @@ export const skipUnmountedBoundaries = false; export const enableNewReconciler = false; export const deferRenderPhaseUpdateToNextBatch = true; -export const decoupleUpdatePriorityFromScheduler = false; export const enableDiscreteEventFlushingChange = false; export const enableStrictEffects = false; diff --git a/packages/shared/forks/ReactFeatureFlags.testing.www.js b/packages/shared/forks/ReactFeatureFlags.testing.www.js index 1dfa34662cd73..65eeaee980825 100644 --- a/packages/shared/forks/ReactFeatureFlags.testing.www.js +++ b/packages/shared/forks/ReactFeatureFlags.testing.www.js @@ -48,7 +48,6 @@ export const skipUnmountedBoundaries = true; export const enableNewReconciler = false; export const deferRenderPhaseUpdateToNextBatch = true; -export const decoupleUpdatePriorityFromScheduler = false; export const enableDiscreteEventFlushingChange = true; export const enableStrictEffects = false; diff --git a/packages/shared/forks/ReactFeatureFlags.www-dynamic.js b/packages/shared/forks/ReactFeatureFlags.www-dynamic.js index 416dfb6191442..a550d45be2d19 100644 --- a/packages/shared/forks/ReactFeatureFlags.www-dynamic.js +++ b/packages/shared/forks/ReactFeatureFlags.www-dynamic.js @@ -17,7 +17,6 @@ export const warnAboutSpreadingKeyToJSX = __VARIANT__; export const disableInputAttributeSyncing = __VARIANT__; export const enableFilterEmptyStringAttributesDOM = __VARIANT__; export const enableLegacyFBSupport = __VARIANT__; -export const decoupleUpdatePriorityFromScheduler = __VARIANT__; export const skipUnmountedBoundaries = __VARIANT__; // Enable this flag to help with concurrent mode debugging. diff --git a/packages/shared/forks/ReactFeatureFlags.www.js b/packages/shared/forks/ReactFeatureFlags.www.js index f1fb6d499b5f3..e4d0b079166b4 100644 --- a/packages/shared/forks/ReactFeatureFlags.www.js +++ b/packages/shared/forks/ReactFeatureFlags.www.js @@ -24,7 +24,6 @@ export const { enableFilterEmptyStringAttributesDOM, enableLegacyFBSupport, deferRenderPhaseUpdateToNextBatch, - decoupleUpdatePriorityFromScheduler, enableDebugTracing, skipUnmountedBoundaries, enableStrictEffects,