From 79eafd877ac826eafed75eaefb1d236a9ec0305b Mon Sep 17 00:00:00 2001 From: Rick Hanlon Date: Tue, 2 Mar 2021 16:53:50 -0700 Subject: [PATCH] Use update lane priority to set pending updates on roots --- .../src/ReactFiberWorkLoop.new.js | 21 +++++++++++++++++++ .../src/ReactFiberWorkLoop.old.js | 21 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js index b404837cb25d0..08c12bf821978 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js @@ -597,6 +597,27 @@ export function scheduleUpdateOnFiber( flushSyncCallbackQueue(); } } + } else if (decoupleUpdatePriorityFromScheduler) { + const updateLanePriority = getCurrentUpdateLanePriority(); + + // 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. + updateLanePriority === InputDiscreteLanePriority + ) { + // 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); } else { // Schedule a discrete update but only if it's not Sync. if ( diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js index 0a366eece7321..566874ca705b6 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js @@ -597,6 +597,27 @@ export function scheduleUpdateOnFiber( flushSyncCallbackQueue(); } } + } else if (decoupleUpdatePriorityFromScheduler) { + const updateLanePriority = getCurrentUpdateLanePriority(); + + // 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. + updateLanePriority === InputDiscreteLanePriority + ) { + // 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); } else { // Schedule a discrete update but only if it's not Sync. if (