Skip to content

Commit d745597

Browse files
authored
Use update lane priority to set pending updates on roots (#20918)
1 parent f04bcb8 commit d745597

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

packages/react-reconciler/src/ReactFiberWorkLoop.new.js

+21
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,27 @@ export function scheduleUpdateOnFiber(
598598
flushSyncCallbackQueue();
599599
}
600600
}
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);
601622
} else {
602623
// Schedule a discrete update but only if it's not Sync.
603624
if (

packages/react-reconciler/src/ReactFiberWorkLoop.old.js

+21
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,27 @@ export function scheduleUpdateOnFiber(
598598
flushSyncCallbackQueue();
599599
}
600600
}
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);
601622
} else {
602623
// Schedule a discrete update but only if it's not Sync.
603624
if (

0 commit comments

Comments
 (0)