…her server content
When every child of an element is a component call, the compiler omits the
calls' anchors and the server frames each call's output. If hydration adopted
the element but the server rendered other content inside it, the first call
found no range at the element's first child. A single-root call then cloned
against the cursor still parked on the element (or an ancestor): the diagnostic
named the element, the stale server children stayed, and the rebuilt root was
appended after them. A lite call's recovery removed the adopted element itself.
An anchorless call that finds no range now takes the missing-range path that
non-single-root components use: render between fresh markers without adopting,
report the server node once, and discard the element's server content. Lite
calls get the same path through mountUnframedLite. renderUnframed skips the
report and discard when its claim is client-built, so a later sibling call no
longer destroys an earlier sibling's rebuilt content.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
When hydration adopts an element whose children are all component calls, but the server rendered other content inside it, the first call now reports the server node once, the element's server children are discarded, and the components are built inside the adopted element.
Repro (server renders the first arm, client the second):
Before, in dev and prod: the
<section>was adopted, the diagnostic said "the client expected<i>but the server rendered<section>", and the DOM ended as<section><b class="server">server</b><s>x</s><i>ok</i></section>. The lite variant (<LiteLeaf text={LABEL} />) removed the adopted<section>entirely. After: one diagnostic, "the client expected a component range but the server rendered<b>", and<section><i>ok</i></section>with the same adopted<section>.Why
The compiler omits a component call's anchor only when every child of the host is a component, and the server frames each such call in
<!--[-->…<!--]-->. On a miss, the cursor branch ofcomponentSlotImpl/componentSlotLitelooked athost.firstChild, but it never moved the cursor there:clone()compared against the cursor still parked on the host (or an ancestor, for a nested host). The "cursor outside the target parent" guard inadopt()then built a fresh root without discarding anything.Changes
componentSlotImpl: an anchorless call (anchor === undefined) that finds no server range no longer takes the markerless single-root path during hydration. It takes the missing-range path that non-single-root components already use: render between fresh markers without adopting, report once, and discard the stale server nodes. Anchored andnull-anchor calls are unchanged.componentSlotLite: the same case goes through a new coldmountUnframedLite, which re-enterscomponentSlotLitethroughrenderUnframed.HydrationCapability.renderUnframedtakes a render callback plus the fresh markers. It skips the report and the discard when its claim is client-built (an earlier rebuild already reported and discarded the server's content). This stops a later anchorless sibling from destroying an earlier sibling's rebuilt output, which also happened onmainfor fragment components.Happy-path cost is two comparisons on a slot's first mount.
componentSlotImplbytecode grows 38 bytes with unchanged registers and frame size. Bundle: +480 B minified / +126 B gzip for the full client entry.Validation
pnpm format:check(not run repo-wide;pnpm format:files:checkon every changed file passes)pnpm typecheck(not run repo-wide;pnpm typecheck:filesonruntime.ts, the test, and the.tsrxfixture passes)pnpm test(not run in full; theoctaneandoctane-prodprojects were run, see below)packages/octane/tests/hydration/adopted-host-component-clone.test.ts(dev + prod compile) covers single-root, lite, nested-host, sibling (single-root / lite / fragment), and empty-host rebuilds, asserting final DOM, adopted-host identity, and exactly one structural diagnostic, plus matching-server adoption controls and post-hydration arm switches. All 16 rebuild cases fail onmain. Removing the client-built check fails the sibling cases, and disabling range adoption fails the adoption controls.octane+octane-prodVitest projects on the currentmain(95421bb): 36,836 of 36,837 tests passed. The one failure was a 15 s timeout inbehavior-root.test.tsunder a load average of about 25–45; that file passed 414/414 in both projects on re-run. Earlier runs under heavier load timed out in up to 8 files, and each passed when re-run alone.Timing benchmarks (
hydration-range-compaction,hydration-render-phase-queue) were not trustworthy for the final candidate: other workloads held the machine's load average at 30–70. An earlier quieter alternating run of an intermediate candidate showed every delta inside about ±7% noise.Risk / follow-ups
<!--comp-->markers, like other missing-range rebuilds.componentSlotImpl's inline fresh-subtree closure makes V8 allocate a 14-slot context on every call.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 first-render hydration paths in the core runtime (
componentSlotImpl, lite slots,renderUnframed), changing DOM teardown and mismatch messaging for structural SSR/client divergence.Overview
Fixes hydration when an adopted host element should only contain component calls, but the server left different markup inside (e.g. a mismatched
@ifarm). The client now treats the first anchorless call as a missing component range: emit one structural mismatch, drop the server children, and render components inside the adopted element instead of appending after stale nodes or removing the host (lite).componentSlotImplno longer uses the markerless single-root path during hydration whenanchoris undefined and no<!--[-->range is found; it follows the existing unframed rebuild path.componentSlotLiteaddsmountUnframedLiteand routes that case throughHydrationCapability.renderUnframed, which now accepts a render callback and fresh markers and skips a second discard/report when the claimed node is already client-built—so later sibling anchorless calls do not tear down an earlier sibling’s rebuild. Empty server hosts report “nothing” in dev diagnostics.Adds a changeset (patch) and hydration tests (single-root, lite, nested, siblings, empty host; dev/prod compile).
Reviewed by Cursor Bugbot for commit 37e1606. Bugbot is set up for automated code reviews on this repo. Configure here.