Skip to content

Commit a173f36

Browse files
author
Brian Vaughn
committed
Renamed the freezeInteractionCount flag and replaced one use-case with a method param
1 parent 1428c46 commit a173f36

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

packages/react-reconciler/src/ReactFiberScheduler.js

+11-15
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ let legacyErrorBoundariesThatAlreadyFailed: Set<mixed> | null = null;
245245
// Used for performance tracking.
246246
let interruptedBy: Fiber | null = null;
247247

248-
// Do not increment or decrement interaction counts in the event of suspense timeouts.
249-
// This flag is only used when enableInteractionTracking is true.
250-
let freezeInteractionCount: boolean = false;
248+
// Do not decrement interaction counts in the event of suspense timeouts.
249+
// This would lead to prematurely calling the interaction-complete hook.
250+
let suspenseDidTimeout: boolean = false;
251251

252252
let stashedWorkInProgressProperties;
253253
let replayUnitOfWork;
@@ -778,7 +778,7 @@ function commitRoot(root: FiberRoot, finishedWork: Fiber): void {
778778
} finally {
779779
// Don't update interaction counts if we're frozen due to suspense.
780780
// In this case, we can skip the completed-work check entirely.
781-
if (!freezeInteractionCount) {
781+
if (!suspenseDidTimeout) {
782782
// Now that we're done, check the completed batch of interactions.
783783
// If no more work is outstanding for a given interaction,
784784
// We need to notify the subscribers that it's finished.
@@ -1607,9 +1607,8 @@ function retrySuspendedRoot(
16071607
__interactionsRef.current = root.memoizedInteractions;
16081608
// Because suspense timeouts do not decrement the interaction count,
16091609
// Continued suspense work should also not increment the count.
1610-
freezeInteractionCount = true;
1610+
storeInteractionsForExpirationTime(root, rootExpirationTime, false);
16111611
requestWork(root, rootExpirationTime);
1612-
freezeInteractionCount = false;
16131612
__interactionsRef.current = prevInteractions;
16141613
} else {
16151614
requestWork(root, rootExpirationTime);
@@ -1671,6 +1670,7 @@ function scheduleWorkToRoot(fiber: Fiber, expirationTime): FiberRoot | null {
16711670
function storeInteractionsForExpirationTime(
16721671
root: FiberRoot,
16731672
expirationTime: ExpirationTime,
1673+
updateInteractionCounts: boolean,
16741674
): void {
16751675
if (!enableInteractionTracking) {
16761676
return;
@@ -1681,7 +1681,7 @@ function storeInteractionsForExpirationTime(
16811681
const pendingInteractions = root.pendingInteractionMap.get(expirationTime);
16821682
if (pendingInteractions != null) {
16831683
interactions.forEach(interaction => {
1684-
if (!freezeInteractionCount && !pendingInteractions.has(interaction)) {
1684+
if (updateInteractionCounts && !pendingInteractions.has(interaction)) {
16851685
// Update the pending async work count for previously unscheduled interaction.
16861686
interaction.__count++;
16871687
}
@@ -1692,7 +1692,7 @@ function storeInteractionsForExpirationTime(
16921692
root.pendingInteractionMap.set(expirationTime, new Set(interactions));
16931693

16941694
// Update the pending async work count for the current interactions.
1695-
if (!freezeInteractionCount) {
1695+
if (updateInteractionCounts) {
16961696
interactions.forEach(interaction => {
16971697
interaction.__count++;
16981698
});
@@ -1732,7 +1732,7 @@ function scheduleWork(fiber: Fiber, expirationTime: ExpirationTime) {
17321732
}
17331733

17341734
if (enableInteractionTracking) {
1735-
storeInteractionsForExpirationTime(root, expirationTime);
1735+
storeInteractionsForExpirationTime(root, expirationTime, true);
17361736
}
17371737

17381738
if (
@@ -1845,10 +1845,6 @@ function scheduleCallbackWithExpirationTime(
18451845
root: FiberRoot,
18461846
expirationTime: ExpirationTime,
18471847
) {
1848-
if (enableProfilerTimer) {
1849-
storeInteractionsForExpirationTime(root, expirationTime);
1850-
}
1851-
18521848
if (callbackExpirationTime !== NoWork) {
18531849
// A callback is already scheduled. Check its expiration time (timeout).
18541850
if (expirationTime > callbackExpirationTime) {
@@ -1929,9 +1925,9 @@ function onTimeout(root, finishedWork, suspendedExpirationTime) {
19291925
if (enableInteractionTracking) {
19301926
// Don't update pending interaction counts for suspense timeouts,
19311927
// Because we know we still need to do more work in this case.
1932-
freezeInteractionCount = true;
1928+
suspenseDidTimeout = true;
19331929
flushRoot(root, suspendedExpirationTime);
1934-
freezeInteractionCount = false;
1930+
suspenseDidTimeout = false;
19351931
} else {
19361932
flushRoot(root, suspendedExpirationTime);
19371933
}

0 commit comments

Comments
 (0)