Skip to content

Commit 37195a1

Browse files
committed
fix(hydration): restore seeds before retry and scan past non-elements in skipForeign
1. Seed undo lost after suspend: when a Suspense arm suspends after applying seeds, passSeeds moved the restore closures to the outer hydration without running them. The retry then snapshotted the already-seeded thenable, so a mismatch discardSeeds restored to the seeded state instead of the original pending state. Use discardAndPassSeeds to run the restores before passing them to the outer hydration, so the retry captures the pre-seed state and the outer's own fallback can still run them idempotently. 2. Foreign skip stops at comments: skipForeign returned null immediately when the cursor was a non-element and its scan loop stopped at the first comment or text node. The deopt singleton walk had the same issue. Remove the cursor.nodeType !== 1 bail and scan past all non-element siblings in both skipForeign and the deopt walk, matching React 19's behavior of skipping unmatched nodes in root containers and document singletons.
1 parent 23cc378 commit 37195a1

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

‎packages/octane/src/runtime.ts‎

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19391,6 +19391,20 @@ class HydrationCapability {
1939119391
if (seeded !== null) for (let i = seeded.length - 1; i >= 0; i--) seeded[i]();
1939219392
}
1939319393

19394+
/**
19395+
* Restore the thenables this attempt seeded (so a retry snapshots the
19396+
* pre-seed state) and hand the closures to `outer` for its own fallback
19397+
* to run again, idempotently.
19398+
*/
19399+
discardAndPassSeeds(outer: HydrationCapability | null): void {
19400+
const seeded = this.seeded;
19401+
this.seeded = null;
19402+
if (seeded !== null) {
19403+
for (let i = seeded.length - 1; i >= 0; i--) seeded[i]();
19404+
if (outer !== null) (outer.seeded ??= []).push(...seeded);
19405+
}
19406+
}
19407+
1939419408
/** The attempt is discarded: restore the server nodes it changed. */
1939519409
rollback(): void {
1939619410
const undo = this.undo;
@@ -20830,16 +20844,18 @@ class HydrationCapability {
2083020844
): Node | null {
2083120845
const parent = domNode(cursor).parentNode;
2083220846
if (
20833-
cursor.nodeType !== 1 ||
2083420847
parent === null ||
2083520848
!(
2083620849
(parent === this.rootBlock.parentNode && this.rootBlock.kind === 'root') ||
2083720850
isDocumentSingleton(parent)
2083820851
)
2083920852
)
2084020853
return null;
20841-
for (let node = getNextSibling(cursor); node?.nodeType === 1; node = getNextSibling(node))
20842-
if (template !== null ? hydrationNodeMatches(node, template) : lazyRootMatches(node, lazy!))
20854+
for (let node = getNextSibling(cursor); node !== null; node = getNextSibling(node))
20855+
if (
20856+
node.nodeType === 1 &&
20857+
(template !== null ? hydrationNodeMatches(node, template) : lazyRootMatches(node, lazy!))
20858+
)
2084320859
return node;
2084420860
return null;
2084520861
}
@@ -34559,8 +34575,7 @@ function reconcileDeoptChildren(el: Element, children: any, ownerBlock: Block):
3455934575
let at = up;
3456034576
while (
3456134577
at < unstamped.length &&
34562-
unstamped[at].nodeType === 1 &&
34563-
!isHostElementOfType(unstamped[at] as Element, child.type)
34578+
(unstamped[at].nodeType !== 1 || !isHostElementOfType(unstamped[at] as Element, child.type))
3456434579
)
3456534580
at++;
3456634581
if (at < unstamped.length && unstamped[at].nodeType === 1) up = at;
@@ -39848,10 +39863,11 @@ function renderInitialSuspenseHydration(state: TrySlot, initial: InitialSuspense
3984839863
// arm renders on the client, and its diagnostics describe why.
3984939864
hydration.releaseDiagnostics(diagnostics, failed && !(failure instanceof HydrationMismatch));
3985039865
// The arm's client render reads client data. Seeds an attempt that is
39851-
// retried or replaced settled stay with the enclosing hydration, whose
39852-
// own fallback discards them.
39866+
// retried or replaced are restored so the retry snapshots the pre-seed
39867+
// state; their closures stay with the enclosing hydration, whose own
39868+
// fallback discards them.
3985339869
if (failure instanceof HydrationMismatch) hydration.discardSeeds();
39854-
else if (failed) hydration.passSeeds(previousHydration);
39870+
else if (failed) hydration.discardAndPassSeeds(previousHydration);
3985539871
setNativeAdoptionResolver(previousNative);
3985639872
WIP_CAPTURE = previousCapture;
3985739873
currentHydration = previousHydration;

0 commit comments

Comments
 (0)