Skip to content

Commit 79eafd8

Browse files
committed
Use update lane priority to set pending updates on roots
1 parent d857f9e commit 79eafd8

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,27 @@ export function scheduleUpdateOnFiber(
597597
flushSyncCallbackQueue();
598598
}
599599
}
600+
} else if (decoupleUpdatePriorityFromScheduler) {
601+
const updateLanePriority = getCurrentUpdateLanePriority();
602+
603+
// Schedule a discrete update but only if it's not Sync.
604+
if (
605+
(executionContext & DiscreteEventContext) !== NoContext &&
606+
// Only updates at user-blocking priority or greater are considered
607+
// discrete, even inside a discrete event.
608+
updateLanePriority === InputDiscreteLanePriority
609+
) {
610+
// This is the result of a discrete event. Track the lowest priority
611+
// discrete update per root so we can flush them early, if needed.
612+
if (rootsWithPendingDiscreteUpdates === null) {
613+
rootsWithPendingDiscreteUpdates = new Set([root]);
614+
} else {
615+
rootsWithPendingDiscreteUpdates.add(root);
616+
}
617+
}
618+
// Schedule other updates after in case the callback is sync.
619+
ensureRootIsScheduled(root, eventTime);
620+
schedulePendingInteractions(root, lane);
600621
} else {
601622
// Schedule a discrete update but only if it's not Sync.
602623
if (

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,27 @@ export function scheduleUpdateOnFiber(
597597
flushSyncCallbackQueue();
598598
}
599599
}
600+
} else if (decoupleUpdatePriorityFromScheduler) {
601+
const updateLanePriority = getCurrentUpdateLanePriority();
602+
603+
// Schedule a discrete update but only if it's not Sync.
604+
if (
605+
(executionContext & DiscreteEventContext) !== NoContext &&
606+
// Only updates at user-blocking priority or greater are considered
607+
// discrete, even inside a discrete event.
608+
updateLanePriority === InputDiscreteLanePriority
609+
) {
610+
// This is the result of a discrete event. Track the lowest priority
611+
// discrete update per root so we can flush them early, if needed.
612+
if (rootsWithPendingDiscreteUpdates === null) {
613+
rootsWithPendingDiscreteUpdates = new Set([root]);
614+
} else {
615+
rootsWithPendingDiscreteUpdates.add(root);
616+
}
617+
}
618+
// Schedule other updates after in case the callback is sync.
619+
ensureRootIsScheduled(root, eventTime);
620+
schedulePendingInteractions(root, lane);
600621
} else {
601622
// Schedule a discrete update but only if it's not Sync.
602623
if (

0 commit comments

Comments
 (0)