Skip to content

Commit d7b9b98

Browse files
committed
fix: deduplicate deferred retry calls per owner in runDeferredSwaps
When multiple useDeferredValue slots share the same root owner and are all disposed (e.g. after a root-level suspension rollback), each slot called owner.retry(true) independently. The first retry synchronously remounts the entire root; if that mount suspends, the second retry starts another mount, incrementing the generation and orphaning the first retry's ping closure. The original wakeable's settlement then never commits because its generation guard fails. Track which owners have already been retried within a single runDeferredSwaps pass so each owner retries at most once.
1 parent b7c7baa commit d7b9b98

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎packages/octane/src/runtime/engine.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5031,6 +5031,7 @@ export function useTransition(
50315031
* is queued (spawnDeferredSwap). Async act() keeps draining while it is set.
50325032
*/
50335033
let DEFERRED_SWAPS: Array<DeferredSlot<any>> | null = null;
5034+
let DEFERRED_RETRIED: Set<RootRenderOwner> | undefined;
50345035

50355036
/**
50365037
* Schedule the deferred current→next swap in a later host task (#1864). A
@@ -5071,6 +5072,7 @@ export function runDeferredSwaps(): void {
50715072
for (let i = 0; i < slots.length; i++) swapDeferredValue(slots[i]);
50725073
} finally {
50735074
TRANSITION_TASK_ACTIVE = false;
5075+
DEFERRED_RETRIED = undefined;
50745076
}
50755077
}
50765078

@@ -5087,9 +5089,12 @@ function swapDeferredValue<T>(s: DeferredSlot<T>): void {
50875089
if (
50885090
owner !== undefined &&
50895091
owner.wakeable !== null &&
5090-
(owner.current === null || owner.current.disposed)
5091-
)
5092+
(owner.current === null || owner.current.disposed) &&
5093+
!(DEFERRED_RETRIED ??= new Set()).has(owner)
5094+
) {
5095+
DEFERRED_RETRIED.add(owner);
50925096
owner.retry(true);
5097+
}
50935098
return;
50945099
}
50955100
if (Object.is(s.value, s.next)) return;

0 commit comments

Comments
 (0)