Use update lane priority to set pending updates on roots (#20918)
Ricky committed
Mar 7, 2021 at 18:43 UTC
d74559746c03d9f620e4fd338c70ce319070e0be
2 files changed
+42
packages/react-reconciler/src/ReactFiberWorkLoop.new.js
+21
@@ -598,6 +598,27 @@ export function scheduleUpdateOnFiber(
598
flushSyncCallbackQueue();
599
}
600
}
601
+ } else if (decoupleUpdatePriorityFromScheduler) {
602
+ const updateLanePriority = getCurrentUpdateLanePriority();
603
+
604
+ // Schedule a discrete update but only if it's not Sync.
605
+ if (
606
+ (executionContext & DiscreteEventContext) !== NoContext &&
607
+ // Only updates at user-blocking priority or greater are considered
608
+ // discrete, even inside a discrete event.
609
+ updateLanePriority === InputDiscreteLanePriority
610
+ ) {
611
+ // This is the result of a discrete event. Track the lowest priority
612
+ // discrete update per root so we can flush them early, if needed.
613
+ if (rootsWithPendingDiscreteUpdates === null) {
614
+ rootsWithPendingDiscreteUpdates = new Set([root]);
615
+ } else {
616
+ rootsWithPendingDiscreteUpdates.add(root);
617
+ }
618
+ }
619
+ // Schedule other updates after in case the callback is sync.
620
+ ensureRootIsScheduled(root, eventTime);
621
+ schedulePendingInteractions(root, lane);
622
} else {
623
// Schedule a discrete update but only if it's not Sync.
624
if (
packages/react-reconciler/src/ReactFiberWorkLoop.old.js
+21
@@ -598,6 +598,27 @@ export function scheduleUpdateOnFiber(
598
flushSyncCallbackQueue();
599
}
600
}
601
+ } else if (decoupleUpdatePriorityFromScheduler) {
602
+ const updateLanePriority = getCurrentUpdateLanePriority();
603
+
604
+ // Schedule a discrete update but only if it's not Sync.
605
+ if (
606
+ (executionContext & DiscreteEventContext) !== NoContext &&
607
+ // Only updates at user-blocking priority or greater are considered
608
+ // discrete, even inside a discrete event.
609
+ updateLanePriority === InputDiscreteLanePriority
610
+ ) {
611
+ // This is the result of a discrete event. Track the lowest priority
612
+ // discrete update per root so we can flush them early, if needed.
613
+ if (rootsWithPendingDiscreteUpdates === null) {
614
+ rootsWithPendingDiscreteUpdates = new Set([root]);
615
+ } else {
616
+ rootsWithPendingDiscreteUpdates.add(root);
617
+ }
618
+ }
619
+ // Schedule other updates after in case the callback is sync.
620
+ ensureRootIsScheduled(root, eventTime);
621
+ schedulePendingInteractions(root, lane);
622
} else {
623
// Schedule a discrete update but only if it's not Sync.
624
if (