Skip to content

Commit

Permalink
Clear finished discrete updates during commit phase
Browse files Browse the repository at this point in the history
If a root is finished at a priority lower than that of the latest pending discrete
updates on it, these updates must have been finished so we can clear them now.
Otherwise, a later call of `flushDiscreteUpdates` would start a new empty render
pass which may cause a scheduled timeout to be cancelled.
  • Loading branch information
jddxf committed Apr 7, 2020
1 parent 98b1762 commit 49f60c1
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/react-reconciler/src/ReactFiberWorkLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,16 @@ function commitRootImpl(root, renderPriorityLevel) {
remainingExpirationTimeBeforeCommit,
);

// Clear already finished discrete updates in case that a later call of
// `flushDiscreteUpdates` starts a useless render pass which may cancels
// a scheduled timeout.
if (rootsWithPendingDiscreteUpdates !== null) {
const lastDiscreteTime = rootsWithPendingDiscreteUpdates.get(root);
if (lastDiscreteTime !== undefined && lastDiscreteTime >= expirationTime) {
rootsWithPendingDiscreteUpdates.delete(root);
}
}

if (root === workInProgressRoot) {
// We can reset these now that they are finished.
workInProgressRoot = null;
Expand Down

0 comments on commit 49f60c1

Please sign in to comment.