Skip to content

Commit c0b08de

Browse files
committed
Retrying a dehydrated boundary pings at the earliest forced time
This might quickly become an already expired time.
1 parent e4209b4 commit c0b08de

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

packages/react-reconciler/src/ReactFiberBeginWork.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ import {
171171
import {
172172
markSpawnedWork,
173173
requestCurrentTime,
174-
retryTimedOutBoundary,
174+
retryDehydratedSuspenseBoundary,
175175
scheduleWork,
176176
} from './ReactFiberWorkLoop';
177177

@@ -2081,7 +2081,7 @@ function updateDehydratedSuspenseComponent(
20812081
// Register a callback to retry this boundary once the server has sent the result.
20822082
registerSuspenseInstanceRetry(
20832083
suspenseInstance,
2084-
retryTimedOutBoundary.bind(null, current),
2084+
retryDehydratedSuspenseBoundary.bind(null, current),
20852085
);
20862086
return null;
20872087
} else {

packages/react-reconciler/src/ReactFiberWorkLoop.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type {
1616
} from './SchedulerWithReactIntegration';
1717
import type {Interaction} from 'scheduler/src/Tracing';
1818
import type {SuspenseConfig} from './ReactFiberSuspenseConfig';
19+
import type {SuspenseState} from './ReactFiberSuspenseComponent';
1920

2021
import {
2122
warnAboutDeprecatedLifecycles,
@@ -2183,18 +2184,23 @@ export function pingSuspendedRoot(
21832184
scheduleCallbackForRoot(root, priorityLevel, suspendedTime);
21842185
}
21852186

2186-
export function retryTimedOutBoundary(boundaryFiber: Fiber) {
2187+
function retryTimedOutBoundary(
2188+
boundaryFiber: Fiber,
2189+
retryTime: ExpirationTime,
2190+
) {
21872191
// The boundary fiber (a Suspense component or SuspenseList component)
21882192
// previously was rendered in its fallback state. One of the promises that
21892193
// suspended it has resolved, which means at least part of the tree was
21902194
// likely unblocked. Try rendering again, at a new expiration time.
21912195
const currentTime = requestCurrentTime();
2192-
const suspenseConfig = null; // Retries don't carry over the already committed update.
2193-
const retryTime = computeExpirationForFiber(
2194-
currentTime,
2195-
boundaryFiber,
2196-
suspenseConfig,
2197-
);
2196+
if (retryTime === Never) {
2197+
const suspenseConfig = null; // Retries don't carry over the already committed update.
2198+
retryTime = computeExpirationForFiber(
2199+
currentTime,
2200+
boundaryFiber,
2201+
suspenseConfig,
2202+
);
2203+
}
21982204
// TODO: Special case idle priority?
21992205
const priorityLevel = inferPriorityFromExpirationTime(currentTime, retryTime);
22002206
const root = markUpdateTimeFromFiberToRoot(boundaryFiber, retryTime);
@@ -2203,12 +2209,26 @@ export function retryTimedOutBoundary(boundaryFiber: Fiber) {
22032209
}
22042210
}
22052211

2212+
export function retryDehydratedSuspenseBoundary(boundaryFiber: Fiber) {
2213+
const suspenseState: null | SuspenseState = boundaryFiber.memoizedState;
2214+
let retryTime = Never;
2215+
if (suspenseState !== null) {
2216+
retryTime = suspenseState.retryTime;
2217+
}
2218+
retryTimedOutBoundary(boundaryFiber, retryTime);
2219+
}
2220+
22062221
export function resolveRetryThenable(boundaryFiber: Fiber, thenable: Thenable) {
2222+
let retryTime = Never; // Default
22072223
let retryCache: WeakSet<Thenable> | Set<Thenable> | null;
22082224
if (enableSuspenseServerRenderer) {
22092225
switch (boundaryFiber.tag) {
22102226
case SuspenseComponent:
22112227
retryCache = boundaryFiber.stateNode;
2228+
const suspenseState: null | SuspenseState = boundaryFiber.memoizedState;
2229+
if (suspenseState !== null) {
2230+
retryTime = suspenseState.retryTime;
2231+
}
22122232
break;
22132233
default:
22142234
invariant(
@@ -2227,7 +2247,7 @@ export function resolveRetryThenable(boundaryFiber: Fiber, thenable: Thenable) {
22272247
retryCache.delete(thenable);
22282248
}
22292249

2230-
retryTimedOutBoundary(boundaryFiber);
2250+
retryTimedOutBoundary(boundaryFiber, retryTime);
22312251
}
22322252

22332253
// Computes the next Just Noticeable Difference (JND) boundary.

0 commit comments

Comments
 (0)