Repository navigation
fix(hydration): discard the server tail of an adopted component range - #1576
Merged
Merged
Conversation
A component's server range can hold more than the client renders into it from the same source: a component whose identity differs on the client, a hookless component in a renderable hole, or a component that returns less. The client adopted the matching prefix and kept the rest on screen without a report. The first render into an adopted range now opens a claim. The template that adopts the range's first node records where its roots end (claimRoots), using the root count the compiler now passes to template(), so production hydration stays template-free. After the render, the server content left before the range's end is removed and reported once (code 51, plus a located development warning). Claims cover componentSlotImpl's adopted frame, componentSlotLite's adopted frame, and childSlot's adopted or lent ranges whose value is a component. A passthrough root's owner is excluded, since it adopts whatever range the server rendered first. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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)
28 other measured values are unchanged. Public-import reachability bundles (bytes)
72 other measured values are unchanged. |
Resolve runtime.ts conflicts with #1567: keep both the in-place adoption (renderInPlace, the inPlace check in adopt()) and the component-range claims (beginClaim/endClaim/renderClaimed/settleClaim, the claimRoots check in adopt()). Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
October 2, 2026 15:42
2 of 5 tasks
trueadm
pushed a commit
that referenced
this pull request
Oct 2, 2026
Resolve runtime.ts against #1561, #1567 and #1576: keep main's adopted-range claims (renderClaimed) and in-place lite rendering (renderInPlace) beside the unframed-claim changes. #1567 renders a lite call that found no range against the cursor, so a hookless component that renders nothing leaves the server element to the next call. Drop this branch's routing of such calls through the missing-range path, which contradicted that. Fix the over-sweep where it happens instead: when such a call rebuilds its fragment, placeRebuilt now discards only the server content in its place, up to the next marker, and drainFrag inserts the fragment there, ahead of later siblings' ranges. The development diagnostic names the call site. renderUnframed shares the same bounded sweep (discardInPlace). The fixture's FragChild gets a hook so it is a full component call in both compiles, which is the path that case covers. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LqA51dmsggKyu7uH3zc9N2
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
During hydration, a component's server range can hold more than the client renders into it, even when server and client run the same source:
const C = props.server ? A : B; <C />);{props.server ? <A /> : <B />}, lite frames in a dev compile);if (props.server) return <><i/><s/></>; return <i/>;), rendered into its return slot's range;When the server's content starts with what the client renders, the client adopted that prefix and kept the rest on screen, with no report.
Now the first render into an adopted range opens a claim. The template that adopts the range's first node records where its roots end (
claimRoots). After the render, hydration removes the server content left before the range's end and reports it once: code 51 throughonRecoverableError, plus a located development warning. The nodes the client adopted keep their identity.Claims cover:
liteRanges);To find where a multi-root template's roots end without parsing it in production, the compiler now passes the template's root count as
template()'sfragargument. The runtime still readsfragonly as truthy elsewhere.A passthrough root's owner (
HYDRATION_RANGE_BOUNDARY) is excluded. By design it adopts whatever range the server rendered first in the container, so its output need not fill that range;range-boundary.test.tscovers this.Relation to other tail fixes
@if/@switcharm leaves unclaimed. This PR does not touch arms. It introduces the shared claim infrastructure (beginClaim/endClaim/renderClaimed/settleClaim,claimRoots, the compiler root count) for component ranges only.renderClaimedinstead of adding a second copy. fix(hydration): discard the server content an adopted @if/@switch arm leaves unclaimed #1565 is closed.@foritem ranges and@trybodies have the same gap only when server and client sources differ. They are out of scope here.Validation
pnpm format:check: not run repo-wide;pnpm format:files:checkon every changed file passes.pnpm typecheck: not run repo-wide;pnpm typecheck:fileson every changed file, including the.tsrxfixture, passes.pnpm test: not run on this head, per the current local-load rule; CI covers it. Before the rebase onto fix(hydration): rebuild component calls in an adopted element with other server content #1563/fix(hydration): discard server ranges a shorter @if/@switch arm leaves unclaimed #1564, the fulloctaneproject passed apart from a stale-install issue, and only this PR's new tests triggered the new discard.packages/octane/tests/hydration/adopted-component-tail.test.tscovers 5 shapes in dev compile, prod compile, and prod compile with the prod runtime (vi.stubEnv('NODE_ENV', 'production')). Each case asserts final DOM, adopted-node identity, removal, exactly one recoverable error and one located dev warning, and an update afterwards. Controls assert that matching server output reports nothing and parses no template in production. 15 cases fail on main, and disabling each owner's hook turns its cases red. 45/45 pass on this head (octane), and the file also passed inoctane-prodbefore the rebase.packages/octane/tests/compiler/template-root-count.test.tschecks that the compiler's root count matches the parsed roots for every fixture template.pnpm sync: clean.Performance
node benchmarks/bundle-size/run-minimal.mjsvs main): hydrate-root +1,437 raw / +413 gzip, deferred-hydration +1,491 / +473, client-only scenarios +0 to +116 raw. These numbers predate a later trim of about 100 raw bytes.node benchmarks/bench.mjs news --ratios):ratios.jsonhas nonewsguards, so octane/svelte hydrate ratios were compared by hand. Four interleaved base/candidate rounds on prebuilt dists gave a median paired octane-tsrx hydrate delta of +0.02 ms, inside noise; the load average was 40–55. The news page has only three hydration markers, so it barely reaches the new path.Risk / follow-ups
@foritems and@trybodies (different-source deployments only) remain.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Changes core hydration DOM reconciliation and compiler
template()metadata; incorrect root counts or claim boundaries could remove valid nodes or miss mismatches, though tests cover multiple shapes and compile/runtime modes.Overview
Hydration now removes leftover server DOM when a component adopts a range but the client renders less than the server put there (dynamic component identity, lite holes, shorter returns, list-item ranges). A claim tracks where the client’s roots end (
beginClaim/claimRoots/settleClaim); anything still inside the frame before the range end is removed, reported once viaonRecoverableError(error #51), and surfaced in dev with a located structural warning. Adopted nodes keep their identity.The compiler passes each multi-root template’s actual root count as
template()’s third argument (replacing a constant1) so production hydration can bound adopted fragment roots without parsing the template HTML. Inspect output and types exposens/fragfor tooling.Component, lite, and child slot paths route adopted-frame first renders through
renderClaimed; passthrough range owners are unchanged. New hydration and compiler tests cover five mismatch shapes and root-count correctness across fixtures.Reviewed by Cursor Bugbot for commit 4cef4bb. Bugbot is set up for automated code reviews on this repo. Configure here.