Repository navigation
fix(hydration): rebuild a hole-first fragment over another arm's nodes - #1599
Merged
Merged
Conversation
A nested fragment whose first root is a hole (a component call, text hole, renderable hole, nested block or boundary) matched any server node, so when the server rendered another @if arm there, hydration adopted that arm's nodes as the fragment's roots. Its static roots were never built, a component in the hole took a server node as its anchor, and the rebuilt root's tail sweep then removed the server node that stood in for them. fragmentRootMatches and lazyFragmentRootMatches now compare the first static element root after the leading holes with the server node the compiled walk reaches from the cursor (HydrationCapability.sibling); the lazy path scans the template source, so production hydration still never parses on the happy path. A mismatch rebuilds the fragment on the client with one report, as for a fragment that starts with a static root, and the development warning names that root. A HYDRATION_RANGE_BOUNDARY passthrough root, whose owner adopts one range level off, keeps the previous behavior (passthroughRoot). Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
October 2, 2026 19:03
Contributor
Benchmark report
Compares js-framework: 1k/10k row operations (ms, lower is better)All 20 timed operations (20 within noise)
Application bundle size (bytes)No changes across 45 measured values. Public-import reachability bundles (bytes)
93 other measured values are unchanged. |
trueadm
added a commit
that referenced
this pull request
Oct 2, 2026
Resolve runtime.ts against #1585 and #1599. #1585 reports a mismatched range once across sibling components: the discard runs before the report, which is skipped when the discard stopped at a range end an earlier recovery already reported (firstAtRangeEnd). renderUnframed keeps that order with this branch's discardInPlace, which returns where it stopped. placeRebuilt's in-place discard also records a range end it reaches (reachedRangeEnd), as its other discard does. #1599 names the static root after a fragment's leading holes in the rebuilt-fragment warning. That warning now lives in placeRebuilt, so it takes the template from the rebuilt record and keeps the lite call's site. 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
Hydration now rebuilds a nested fragment that starts with a hole when the server rendered something else there, such as the other
@ifarm.A leading hole (a component call, text hole, renderable hole, nested block, or boundary) matched any server node in
fragmentRootMatches/lazyFragmentRootMatches. Repro: an@elsearm<><Under v="z" /><i>x</i></>hydrated over the server's then-arm<b>…</b><em>e</em>. Hydration adopted the server nodes as the fragment's roots. The static<i>x</i>was never built, andUnder's slot took the server<b>as its anchor. AfterUnderrebuilt<u>in place of<b>, the rebuilt-tail sweep removed<em>, so the section read<u>z</u>. Before #1561 the same shape threwNotFoundErrorsynchronously fromcommitBag, which inserted before the discarded<b>.fragmentRootMatches(parsed templates) andlazyFragmentRootMatches(production, read from the template source) now skip the leading<!>holes. They compare the first static element root with the server node the compiled walk reaches from the cursor,HydrationCapability.sibling(cursor, holes). The lazy path only scans the source, so production hydration still never parses a template on the happy path.adopt()callsrebuildFragment, which reports once, as it already did for fragments that start with a static root. The development warning names the root that differed: "the client expected a fragment with<i>after its leading holes but the server rendered<em>".HYDRATION_RANGE_BOUNDARYpassthrough root (the newHydrationCapability.passthroughRoot). There the owner adopts the first server range in the container, so its content can sit one range level off (range-boundary.test.ts, "keeps a multi-root owner…", fails without the gate).Why rebuild instead of keeping the in-place slot's anchor valid: a valid anchor cannot bring back the fragment's missing static roots. With the rebuild, a component in the hole also mounts inside the fresh clone, so its anchor is a client node, and a later
keychange remounts it normally.Validation
pnpm format:check(not run;pnpm format:files:checkon the changed files passes)pnpm typecheck(not run;pnpm typecheck:fileson the changed files, with the.tsrxfixture passed explicitly, passes)pnpm test(not run, because of local machine load)packages/octane/tests/hydration/arm-hole-first-fragment.test.tsplus a fixture. Every case runs under both compiles and both runtimes (production viavi.stubEnv), 52 tests.@try, and<Suspense>holes first. Each must adopt the server nodes with no report.packages/octane/tests/hydrationpasses inoctaneandoctane-prodafter merging current main (131 files each). Before the merge, it passed together with the 124 otherpackages/octane/testsfiles that callhydrateRoot(253 files per project).benchmarks/bundle-size/run-minimal.mjs, vs main):hydrate-rootdeferred-hydrationroot-static,hooks-state(client-only)sibling()steps whose close-marker lookups are cached and would be done by the adopting slot anyway. No hydration benchmark was run.website/tests/ssr-hydration.e2e.test.ts.Risk / follow-ups
If the sibling
claimRootsshort-range fix lands, it introduces a field with the same name,passthroughRoot. Whichever PR lands second should merge them into one.Out of scope, and also failing on main: when the server's other arm matches the fragment's static roots, the fragment is correctly adopted, but a component hole whose server node is a bare element still goes wrong:
renderUnframedstops at its own anchor.These are being fixed separately.
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 in
runtime.tsfor nested fragments and@ifarms; incorrect logic could cause extra rebuilds or regress range-boundary hydration, though mismatches fail safe via client rebuild.Overview
Fixes hydration when a nested fragment’s first logical root is a dynamic hole (component, text, block, etc.) but the server HTML came from a different branch (e.g. the other
@ifarm). Previously those holes matched any server node, so the client adopted the wrong subtree, skipped static roots, and mis-anchored components in the hole.fragmentRootMatchesandlazyFragmentRootMatchesnow walk past leading<!>holes and compare the first static element to the server node athydration.sibling(cursor, holeCount). On mismatch, hydration rebuilds the fragment (one recoverable error #51), same as for a static-first fragment. Dev warnings call out the expected static root after leading holes vs what the server had.HydrationCapability.passthroughRootgates this check forHYDRATION_RANGE_BOUNDARYpassthrough roots so range-boundary adoption behavior is unchanged.Adds a changeset, fixture, and broad
hydrateRoottests (mismatch rebuilds + matching adoption controls across dev/prod compile and runtime).Reviewed by Cursor Bugbot for commit 4f65b8d. Bugbot is set up for automated code reviews on this repo. Configure here.