Skip to content

Commit 8458a4c

Browse files
committed
fix(octane): prevent independent reveal groups from stranding hidden boundaries and stale settles from clearing active timeouts
Bug 1: stagedRevealGroup() concatenated all ready groups into one flat array. flushStagedReveals treated that as a single batch, so a visible member's retry removed unrelated hidden boundaries from STAGED_REVEALS, stranding them with no wake path. Fix: return only the first ready group and loop in flushStagedRevealsIfReady so each group flushes independently. Bug 2: The HELD_TRANSITIONS exception in attachResume's retry closure allowed stale thenables to proceed, but unconditionally cleared pendingThenable and transitionTimeoutId. A stale settle disarmed the timeout that was armed for the current (fresher) thenable, preventing a finite fallback budget from firing. Fix: guard the cleanup so only the current thenable's settle clears tracking state.
1 parent 4689d76 commit 8458a4c

2 files changed

Lines changed: 18 additions & 13 deletions

File tree

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2889,8 +2889,12 @@ export function flushStagedRevealsIfReady(): void {
28892889
for (const state of STAGED_REVEALS) {
28902890
if (!HELD_TRANSITIONS.has(state)) STAGED_REVEALS.delete(state);
28912891
}
2892-
const group = STAGED_REVEALS.size === 0 ? null : stagedRevealGroup();
2893-
if (group !== null) flushStagedReveals(group);
2892+
// Process one group at a time: each flush removes its members from
2893+
// STAGED_REVEALS, so independent groups never share a single batch.
2894+
let group: TrySlot[] | null;
2895+
while ((group = STAGED_REVEALS.size === 0 ? null : stagedRevealGroup()) !== null) {
2896+
flushStagedReveals(group);
2897+
}
28942898
}
28952899

28962900
function compareStagedRevealDomOrder(a: TrySlot, b: TrySlot): number {
@@ -2979,16 +2983,18 @@ export function attachResume(state: TrySlot, thenable: TrackedThenable<any>): vo
29792983
// A fresher suspend supersedes this one, unless the boundary holds
29802984
// transitions: each holds its own batches (Transition holds), so any
29812985
// thenable they suspended on may let one of them commit.
2982-
if (state.pendingThenable !== thenable && !HELD_TRANSITIONS.has(state)) return;
2986+
const isCurrent = state.pendingThenable === thenable;
2987+
if (!isCurrent && !HELD_TRANSITIONS.has(state)) return;
29832988
if (typeof __OCTANE_PROFILE_ENABLED__ !== 'undefined' && __OCTANE_PROFILE_ENABLED__)
29842989
__profileCount(ProfileCounter.BOUNDARY_RETRY);
2985-
state.pendingThenable = null;
2986-
// Cancel any pending transition-fallback timeout — the promise resolved
2987-
// before the timeout would have swapped to @pending, so the prior DOM
2988-
// stays put and the just-resolved render commits over it directly.
2989-
if (state.transitionTimeoutId !== null) {
2990-
clearTimeout(state.transitionTimeoutId);
2991-
state.transitionTimeoutId = null;
2990+
// Only clear tracking state when the current thenable resolves. A stale
2991+
// settle on a held boundary must not disarm the fresher thenable's timeout.
2992+
if (isCurrent) {
2993+
state.pendingThenable = null;
2994+
if (state.transitionTimeoutId !== null) {
2995+
clearTimeout(state.transitionTimeoutId);
2996+
state.transitionTimeoutId = null;
2997+
}
29922998
}
29932999
const persistent = state.tryBlock;
29943000
if (persistent !== null && !persistent.disposed) {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,6 @@ export const STAGED_REVEALS = new Set<TrySlot>();
458458
* parallel transitions. Runs when a boundary stages, on a handful of boundaries.
459459
*/
460460
export function stagedRevealGroup(): TrySlot[] | null {
461-
let ready: TrySlot[] | null = null;
462461
const seen = new Set<TrySlot>();
463462
for (const start of STAGED_REVEALS) {
464463
if (seen.has(start)) continue;
@@ -480,9 +479,9 @@ export function stagedRevealGroup(): TrySlot[] | null {
480479
}
481480
}
482481
for (const member of group) seen.add(member);
483-
if (group.every((member) => STAGED_REVEALS.has(member))) (ready ??= []).push(...group);
482+
if (group.every((member) => STAGED_REVEALS.has(member))) return group;
484483
}
485-
return ready;
484+
return null;
486485
}
487486

488487
// ─────────────────────────────────────────────────────────────────────────────

0 commit comments

Comments
 (0)