Skip to content

Commit 46604ca

Browse files
committed
Fix lazy thenable suspension race
1 parent 65eec42 commit 46604ca

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

packages/react-reconciler/src/ReactFiberThenable.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -294,22 +294,26 @@ export function suspendCommit(): void {
294294
throw SuspenseyCommitException;
295295
}
296296

297+
function initLazy<T>(lazyType: LazyComponentType<T, any>): T {
298+
if (__DEV__) {
299+
return callLazyInitInDEV(lazyType);
300+
}
301+
const payload = lazyType._payload;
302+
const init = lazyType._init;
303+
return init(payload);
304+
}
305+
297306
export function resolveLazy<T>(lazyType: LazyComponentType<T, any>): T {
298307
try {
299-
if (__DEV__) {
300-
return callLazyInitInDEV(lazyType);
301-
}
302-
const payload = lazyType._payload;
303-
const init = lazyType._init;
304-
return init(payload);
308+
return initLazy(lazyType);
305309
} catch (x) {
306310
if (x !== null && typeof x === 'object' && typeof x.then === 'function') {
307-
// This lazy Suspended. Treat this as if we called use() to unwrap it.
308-
suspendedThenable = x;
309-
if (__DEV__) {
310-
needsToResetSuspendedThenableDEV = true;
311-
}
312-
throw SuspenseException;
311+
// This lazy suspended. Treat this as if we called use() to unwrap it,
312+
// so we attach the same thenable bookkeeping immediately.
313+
const thenableState = createThenableState();
314+
trackUsedThenable(thenableState, (x: any), 0);
315+
// If the thenable resolved synchronously, try again.
316+
return initLazy(lazyType);
313317
}
314318
throw x;
315319
}

0 commit comments

Comments
 (0)