Skip to content

Commit

Permalink
Use update lane priority to set pending updates on roots
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii committed Mar 2, 2021
1 parent d857f9e commit 79eafd8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
21 changes: 21 additions & 0 deletions packages/react-reconciler/src/ReactFiberWorkLoop.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 79eafd8

Please sign in to comment.