Skip to content

Commit dea6d03

Browse files
committed
Rename retryTimedOutBoundary to resolveRetryThenable
This doesn't just retry. It assumes that resolving a thenable means that it is ok to clear it from the thenable cache. We'll reuse the retryTimedOutBoundary logic separately.
1 parent 37f74c4 commit dea6d03

File tree

5 files changed

+26
-36
lines changed

5 files changed

+26
-36
lines changed

packages/react-reconciler/src/ReactFiberBeginWork.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ import {
8484
import {
8585
shouldSetTextContent,
8686
shouldDeprioritizeSubtree,
87+
isSuspenseInstancePending,
88+
isSuspenseInstanceFallback,
8789
} from './ReactFiberHostConfig';
90+
import type {SuspenseInstance} from './ReactFiberHostConfig';
8891
import {pushHostContext, pushHostContainer} from './ReactFiberHostContext';
8992
import {
9093
pushProvider,
@@ -107,8 +110,6 @@ import {
107110
import {
108111
enterHydrationState,
109112
reenterHydrationStateFromDehydratedSuspenseInstance,
110-
isDehydratedSuspenseComponentPending,
111-
isDehydratedSuspenseComponentFallback,
112113
resetHydrationState,
113114
tryToClaimNextHydratableInstance,
114115
} from './ReactFiberHydrationContext';
@@ -1648,10 +1649,11 @@ function updateDehydratedSuspenseComponent(
16481649
// We use childExpirationTime to indicate that a child might depend on context, so if
16491650
// any context has changed, we need to treat is as if the input might have changed.
16501651
const hasContextChanged = current.childExpirationTime >= renderExpirationTime;
1652+
const suspenseInstance = (current.stateNode: SuspenseInstance);
16511653
if (
16521654
didReceiveUpdate ||
16531655
hasContextChanged ||
1654-
isDehydratedSuspenseComponentFallback(current)
1656+
isSuspenseInstanceFallback(suspenseInstance)
16551657
) {
16561658
// This boundary has changed since the first render. This means that we are now unable to
16571659
// hydrate it. We might still be able to hydrate it using an earlier expiration time but
@@ -1693,7 +1695,7 @@ function updateDehydratedSuspenseComponent(
16931695
workInProgress.effectTag |= Placement;
16941696
// Retry as a real Suspense component.
16951697
return updateSuspenseComponent(null, workInProgress, renderExpirationTime);
1696-
} else if (isDehydratedSuspenseComponentPending(current)) {
1698+
} else if (isSuspenseInstancePending(suspenseInstance)) {
16971699
// This component is still pending more data from the server, so we can't hydrate its
16981700
// content. We treat it as if this component suspended itself. It might seem as if
16991701
// we could just try to render it client-side instead. However, this will perform a

packages/react-reconciler/src/ReactFiberCommitWork.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ import {
9494
import {
9595
captureCommitPhaseError,
9696
requestCurrentTime,
97-
retryTimedOutBoundary,
97+
resolveRetryThenable,
9898
} from './ReactFiberScheduler';
9999
import {
100100
NoEffect as NoHookEffect,
@@ -1232,7 +1232,7 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
12321232
}
12331233
thenables.forEach(thenable => {
12341234
// Memoize using the boundary fiber to prevent redundant listeners.
1235-
let retry = retryTimedOutBoundary.bind(null, finishedWork, thenable);
1235+
let retry = resolveRetryThenable.bind(null, finishedWork, thenable);
12361236
if (enableSchedulerTracing) {
12371237
retry = Schedule_tracing_wrap(retry);
12381238
}

packages/react-reconciler/src/ReactFiberHydrationContext.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ import {
3434
canHydrateInstance,
3535
canHydrateTextInstance,
3636
canHydrateSuspenseInstance,
37-
isSuspenseInstancePending,
38-
isSuspenseInstanceFallback,
3937
getNextHydratableSibling,
4038
getFirstHydratableChild,
4139
hydrateInstance,
@@ -86,14 +84,6 @@ function reenterHydrationStateFromDehydratedSuspenseInstance(
8684
return true;
8785
}
8886

89-
function isDehydratedSuspenseComponentPending(fiber: Fiber) {
90-
return isSuspenseInstancePending((fiber.stateNode: SuspenseInstance));
91-
}
92-
93-
function isDehydratedSuspenseComponentFallback(fiber: Fiber) {
94-
return isSuspenseInstanceFallback((fiber.stateNode: SuspenseInstance));
95-
}
96-
9787
function deleteHydratableInstance(
9888
returnFiber: Fiber,
9989
instance: HydratableInstance,
@@ -444,8 +434,6 @@ function resetHydrationState(): void {
444434
export {
445435
enterHydrationState,
446436
reenterHydrationStateFromDehydratedSuspenseInstance,
447-
isDehydratedSuspenseComponentPending,
448-
isDehydratedSuspenseComponentFallback,
449437
resetHydrationState,
450438
tryToClaimNextHydratableInstance,
451439
prepareToHydrateHostInstance,

packages/react-reconciler/src/ReactFiberScheduler.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,20 @@ function pingSuspendedRoot(
16981698
}
16991699
}
17001700

1701-
function retryTimedOutBoundary(boundaryFiber: Fiber, thenable: Thenable) {
1701+
function retryTimedOutBoundary(boundaryFiber: Fiber) {
1702+
const currentTime = requestCurrentTime();
1703+
const retryTime = computeExpirationForFiber(currentTime, boundaryFiber);
1704+
const root = scheduleWorkToRoot(boundaryFiber, retryTime);
1705+
if (root !== null) {
1706+
markPendingPriorityLevel(root, retryTime);
1707+
const rootExpirationTime = root.expirationTime;
1708+
if (rootExpirationTime !== NoWork) {
1709+
requestWork(root, rootExpirationTime);
1710+
}
1711+
}
1712+
}
1713+
1714+
function resolveRetryThenable(boundaryFiber: Fiber, thenable: Thenable) {
17021715
// The boundary fiber (a Suspense component) previously timed out and was
17031716
// rendered in its fallback state. One of the promises that suspended it has
17041717
// resolved, which means at least part of the tree was likely unblocked. Try
@@ -1729,16 +1742,7 @@ function retryTimedOutBoundary(boundaryFiber: Fiber, thenable: Thenable) {
17291742
retryCache.delete(thenable);
17301743
}
17311744

1732-
const currentTime = requestCurrentTime();
1733-
const retryTime = computeExpirationForFiber(currentTime, boundaryFiber);
1734-
const root = scheduleWorkToRoot(boundaryFiber, retryTime);
1735-
if (root !== null) {
1736-
markPendingPriorityLevel(root, retryTime);
1737-
const rootExpirationTime = root.expirationTime;
1738-
if (rootExpirationTime !== NoWork) {
1739-
requestWork(root, rootExpirationTime);
1740-
}
1741-
}
1745+
retryTimedOutBoundary(boundaryFiber);
17421746
}
17431747

17441748
function scheduleWorkToRoot(fiber: Fiber, expirationTime): FiberRoot | null {
@@ -2588,7 +2592,7 @@ export {
25882592
renderDidSuspend,
25892593
renderDidError,
25902594
pingSuspendedRoot,
2591-
retryTimedOutBoundary,
2595+
resolveRetryThenable,
25922596
markLegacyErrorBoundaryAsFailed,
25932597
isAlreadyFailedLegacyErrorBoundary,
25942598
scheduleWork,

packages/react-reconciler/src/ReactFiberUnwindWork.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ import {
6666
markLegacyErrorBoundaryAsFailed,
6767
isAlreadyFailedLegacyErrorBoundary,
6868
pingSuspendedRoot,
69-
retryTimedOutBoundary,
69+
resolveRetryThenable,
7070
} from './ReactFiberScheduler';
7171

7272
import invariant from 'shared/invariant';
@@ -372,11 +372,7 @@ function throwException(
372372
// Memoize using the boundary fiber to prevent redundant listeners.
373373
if (!retryCache.has(thenable)) {
374374
retryCache.add(thenable);
375-
let retry = retryTimedOutBoundary.bind(
376-
null,
377-
workInProgress,
378-
thenable,
379-
);
375+
let retry = resolveRetryThenable.bind(null, workInProgress, thenable);
380376
if (enableSchedulerTracing) {
381377
retry = Schedule_tracing_wrap(retry);
382378
}

0 commit comments

Comments
 (0)