diff --git a/packages/react-reconciler/src/ReactFiberScheduler.js b/packages/react-reconciler/src/ReactFiberScheduler.js index a4b703e98516b..8c91c21c0cb91 100644 --- a/packages/react-reconciler/src/ReactFiberScheduler.js +++ b/packages/react-reconciler/src/ReactFiberScheduler.js @@ -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 { @@ -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. @@ -798,6 +810,8 @@ function commitRoot(root: FiberRoot, finishedWork: Fiber): void { } } }); + } else { + suspenseDidTimeout = false; } } } @@ -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 @@ -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); }