Repository navigation
fix(hydration): mount blocks inside a rebuilt clone as client content - #1552
Merged
Merged
Conversation
When a template's root does not match the server node, hydration reports the mismatch and clones the template fresh on the client. The cursor still points at the server output that follows the mismatch, but the @if, @switch, @for, @Try, Activity, and ErrorBoundary blocks inside the fresh clone kept hydrating against it. Development builds logged a second, false structural mismatch for the same recovery; an @for with an @empty arm threw; and a block could take a following server element, list range, or use() seed as its own, so the rebuilt element showed the wrong content or went missing. Each of those blocks now checks, only once it has found no server range, whether it sits inside a client-built replacement, and if so mounts with hydration suspended, as component and child slots already do. A sole-hole @for also requires the cursor to sit in its own parent before adopting it, the rule resolveOpen applies to the other blocks. A block mismatch inside an adopted server element still reports. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
October 2, 2026 08:36
Contributor
Benchmark report
Compares js-framework: 1k/10k row operations (ms, lower is better)
All 20 timed operations (18 within noise)
Application bundle size (bytes)
15 other measured values are unchanged. Public-import reachability bundles (bytes)
89 other measured values are unchanged. CI job durations
Compares the CI run for
All 26 timed jobs
|
The staged-DOM lint requires a native read to go through a classified receiver. Use the same domNode(hydration.node) idiom childSlot already uses for its cursor-parent check. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a hydrating template's root does not match the server node,
adopt()reports the mismatch and returns a fresh client clone. The hydration cursor still points at the server output that follows the mismatch. The@if,@switch,@for,@try,<Activity>, and<ErrorBoundary>blocks inside that fresh clone found no server range of their own, mounted on the client-mount path, and kept hydrating against that stale cursor. With this change they mount as client content, the same way component and child slots inside a rebuilt clone already do.Why
Before this change, a block inside a rebuilt clone (dev and prod unless noted):
the client expected <s> but the server rendered the end of the parent block, or for@for,the client expected another list item but the server rendered nothing.NotFoundErrorfor an@forwith an@emptyarm, or when a server sibling followed the rebuilt element.@forcould claim the following server list range, rendering its items outside the rebuilt element.use()inside the arm read the following server sibling's positional seed, showing that sibling's value permanently.onRecoverableErrorstill fired once, because recoverable reports coalesce per root per microtask.Changes
HydrationCapability.inFreshRange(anchor, parent): whether a slot sits inside a client-built replacement.ifBlock,switchBlock,forBlock,tryBlock,errorBlock, andactivityBlockask only in their existing "no server range found" branch. SSR always frames these blocks while hydrating, so that branch is off the adoption path. If the slot is inside a rebuilt clone, the call re-enters underhydration.suspend. The re-entry through the returned-output preamble is safe because the reset handler clearsslots[0].forBlock's sole-hole branch now requires the cursor to sit indomParentbefore adopting its range.resolveOpenalready applies this rule for the other blocks. It is the one change on the adoption path: oneparentNoderead per sole-hole@formount while hydrating.tests/hydration/rebuilt-clone-blocks.test.ts, run with dev and prod compiles. It covers each block, the crash, both foreign-claim cases, adopted-sibling identity, and the seed case. Controls confirm a genuine@ifor@formismatch inside an adopted element still reports.Validation
pnpm format:check(not run repo-wide;pnpm format:files:checkon the changed files passes)pnpm typecheck(not run repo-wide;pnpm typecheck:fileson the changed files, with the.tsrxfixture passed explicitly, passes)pnpm test(not run; see the targeted runs below)vitest run --project octane --project octane-prodpassed 35,858/35,859. The one failure was a 5 s timeout inbehavior-root.test.tsat load average ~40; that file passed 414/414 in two isolated reruns.tests/hydration/in both projects instead. 11,452/11,517 passed. All 65 failures were 5 s timeouts or knock-on errors from them ("receiver already installed", "wrong authority"), spread over 18 files. Rerunning those 18 files with--maxWorkers=4left 14 failures in 2 files (signal-instance-identity,text-sibling-hydrate), and both files then passed 117/117 with--testTimeout=60000.rebuilt-clone-blocks.test.ts: 26/26. Against the unpatched runtime, 16 fail (all 10 new dev cases; in prod, the@emptycrash, both foreign-claim cases, adopted-sibling identity, and the seed case). The 4 controls pass either way.pnpm syncleaves the tree clean.ifBlock,forBlock, andtryBlockalways ship and each gains a fresh-host re-entry. The reachability bundles grow by +17 to +41 B gzip (hydrate-root,deferred-hydration,suspense-transition,cli-spa-starter). The minimal signal-free budgets that CI enforces are byte-identical (benchmarks/bundle-size/run-minimal.mjs --budgets ...locally). No wall-clock benchmark: the only adoption-path change is the singleparentNoderead above, which is far below benchmark noise, and the bench's 20 js-framework timings are all within noise.Risk / follow-ups
@forwithout@empty, hydrated with client items, logs two diagnostics, one misworded(@empty). The@forcontrol here uses a non-empty server list, so it does not depend on fix(hydration): report a server-empty list once when the client has items #1542.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Touches core hydration adoption for all major control-flow blocks; behavior changes only when slots sit inside client-rebuilt subtrees, but mistakes could affect DOM correctness or mismatch diagnostics.
Overview
When hydration rebuilds a subtree after a structural mismatch, the cursor can still sit on server siblings that follow the replacement. Control-flow blocks inside that fresh clone (
@if,@switch,@for,@try,<Activity>,<ErrorBoundary>) used to keep adopting/hydrating from that stale cursor when they had no server range of their own.This PR adds
HydrationCapability.inFreshRangeand, in each block’s “no server range” path, re-enters viahydration.suspendso those slots mount as client content (matching component/child slots in rebuilt clones).@foralso requires the hydration cursor to live underdomParentbefore sole-hole range adoption, avoiding cross-range claims.Regression tests cover false second mismatches, foreign server nodes/list ranges, sibling adoption,
use()seeds, and unchanged reporting for real mismatches inside adopted elements.Reviewed by Cursor Bugbot for commit 94ebe32. Bugbot is set up for automated code reviews on this repo. Configure here.