Skip to content

Commit

Permalink
Added potential (somewhat hacky) fix for interaction suspense ref cou…
Browse files Browse the repository at this point in the history
…nting
  • Loading branch information
Brian Vaughn committed Sep 7, 2018
1 parent f8c8030 commit 0d0788e
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions packages/react-reconciler/src/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ import {
computeAsyncExpiration,
computeInteractiveExpiration,
} from './ReactFiberExpirationTime';
import {AsyncMode, ProfileMode} from './ReactTypeOfMode';
import {AsyncMode, ProfileMode, StrictMode} from './ReactTypeOfMode';
import {enqueueUpdate, resetCurrentlyProcessingQueue} from './ReactUpdateQueue';
import {createCapturedValue} from './ReactCapturedValue';
import {
Expand Down Expand Up @@ -777,9 +777,21 @@ function commitRoot(root: FiberRoot, finishedWork: Fiber): void {
unhandledError = error;
}
} finally {
const updateExpirationTime = root.expirationTime;
const childExpirationTime = finishedWork.childExpirationTime;
const earliestRemainingTime =
updateExpirationTime === NoWork ||
(childExpirationTime !== NoWork &&
childExpirationTime < updateExpirationTime)
? childExpirationTime
: updateExpirationTime;
// Don't update interaction counts if we're frozen due to suspense.
// In this case, we can skip the completed-work check entirely.
if (!suspenseDidTimeout) {
if (
!suspenseDidTimeout &&
((finishedWork.mode & StrictMode) !== NoEffect ||
earliestRemainingTime === 0)
) {
// Now that we're done, check the completed batch of interactions.
// If no more work is outstanding for a given interaction,
// We need to notify the subscribers that it's finished.
Expand All @@ -798,6 +810,8 @@ function commitRoot(root: FiberRoot, finishedWork: Fiber): void {
}
}
});
} else {
suspenseDidTimeout = false;
}
}
}
Expand Down Expand Up @@ -1392,6 +1406,7 @@ function renderRoot(
if (enableSuspense && !isExpired && nextLatestAbsoluteTimeoutMs !== -1) {
// The tree was suspended.
const suspendedExpirationTime = expirationTime;
suspenseDidTimeout = true;
markSuspendedPriorityLevel(root, suspendedExpirationTime);

// Find the earliest uncommitted expiration time in the tree, including
Expand Down Expand Up @@ -1928,7 +1943,6 @@ function onTimeout(root, finishedWork, suspendedExpirationTime) {
// Because we know we still need to do more work in this case.
suspenseDidTimeout = true;
flushRoot(root, suspendedExpirationTime);
suspenseDidTimeout = false;
} else {
flushRoot(root, suspendedExpirationTime);
}
Expand Down

0 comments on commit 0d0788e

Please sign in to comment.