Repository navigation
fix(hydration): adopt a component hole's own server node in a template adopted in place - #1602
Merged
Merged
Conversation
…e adopted in place A component call that finds no server range of its own, because the server rendered another @if/@switch arm there, adopts the server markup in place. A component call that is a hole in that template found its in-place root from the hydration cursor, which still sits on the template's first root (a fragment's virtual adoption, or an element template's root), rather than from its walked anchor. When the server rendered the inner call's markup inline, the inner call rendered against that first root, reported a mismatch and replaced a node the outer component had already adopted. - componentSlotLite: an anchored call without a range renders in place of its anchor unless the anchor is its block's end marker (a templateless body, whose cursor is right) or null (a walk that ran off its host). - componentSlotImpl: the single-root branch applies the same rule. Framed calls and adopt() take no extra work. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
October 2, 2026 19:35
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)
29 other measured values are unchanged. Public-import reachability bundles (bytes)
76 other measured values are unchanged. |
This was referenced Oct 2, 2026
trueadm
added a commit
that referenced
this pull request
Oct 2, 2026
… the changeset Main's #1602 and #1600 now handle the single-root and lite calls at a component hole in an adopted arm, so this branch's runtime change is reduced to the unframed (keyed or dynamic) path. A keyed call after the adopted static root pins that its stale node comes from its anchor rather than the lagging cursor, which would delete the adopted root. 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
A component call can find no server range of its own because the server rendered another
@if/@switcharm there. Hydration then adopts the server markup in place. If that component's template contains another component call (a hole), the hole now renders in place of the server node its template walk found. Before, it used the server node at the hydration cursor.Repro, broken on
main:Server-render with
on: false, thenhydrateRootwithon: true.<em>e</em><em>e</em>. The server<i>was replaced and a mismatch was reported.<i>p</i><em>e</em><em>e</em>. Every server element is adopted and nothing is reported.Cause
When a call with an anchor found no range, it took its in-place root from the cursor (or
host.firstChild). For a hole in an adopted template, the cursor is still where the adoption left it:When the server framed the inner call, the anchor was its
<!--[-->and the framed path hid the bug. When the server rendered that markup inline, the inner call rendered against a node the outer component had already adopted, reported a mismatch, and replaced it. Calls with hooks (componentSlotImpl's single-root path) had the same defect.Changes
componentSlotLite, anchored call with no range: the call renders in place of its anchor and parks the cursor there. Two anchors keep the old behaviour:null: a walk that ran off the end of its host, which keepsmain's mismatch report.componentSlotImpl, single-root branch: the same rule.Compiled anchors are only ever a walked
<!>placeholder,__block.endMarker, orundefined(anchorNodeFor), so the end-marker comparison separates template holes from template-less bodies. Framed calls never reach either branch, andadopt()is unchanged.Validation
pnpm format:check(not run; scopedpnpm format:files:checkon the changed files passes)pnpm typecheck(not run; scopedpnpm typecheck:fileson the changed files passes)pnpm test(not run, because of local machine load)tests/hydration/in-place-fragment-hole.test.ts(12 cases, dev and prod compiles).main.main; they pin that behaviour.nullanchors, in both slots, and remove the full-slot change.octaneproject. Among them: in-place component sibling, lite host mismatch, hole-first fragment arm, component range siblings, unframed component siblings, adopted component tail, branch arm tails,hydration,prod-mode-hydrate.componentSlotLiteandcomponentSlotImpl. Locally,benchmarks/bundle-size/run-minimal.mjsgavedeferred-hydration+49 B raw / +16 B gzip / −31 B brotli. I ran no timing benchmark: the runtime changes are on cold no-range branches, plus onehydration !== nullcheck on a client-side single-root mount.Risk / follow-ups
main: a server arm with fewer roots, whose walk lands exactly on the parent block's end marker. That looks the same as a template-less body, so the adopted first root is still replaced.renderUnframedpath). That path stops discarding at the anchor, so pointing it at the walked node would leave the stale server node in place. It needs its own design.<i/><Em/><b/>) is fully clean only together with the in-place fragment cursor fix onfix/unframed-fragment-root(c8cff03afb, unmerged). That fix moves the cursor past every root of an in-place fragment. I checked that the two compose by cherry-picking it locally. On this PR alone the server<i>is kept, but the next sibling still rebuilds over<b>.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 slot logic on no-range and single-root paths; behavior is narrow but incorrect fixes could cause silent DOM corruption or extra mismatches.
Overview
Fixes hydration mismatches when the server rendered a different
@if/@switcharm and the client adopts that markup in place, but a nested component call in the adopted template must hydrate against its own server node—not the cursor still sitting on the template’s first root.In
componentSlotLite, an anchored call with no server range now treats a walked anchor (a template hole) as in-place at that anchor and moves the hydration cursor there;nullor the block end marker still use the previous in-place root behavior. ThecomponentSlotImplsingle-root hydration path applies the same cursor rule.Adds a patch changeset, fixture
in-place-fragment-hole.tsrx, andin-place-fragment-hole.test.ts(dev/prod compiles) covering inline vs framed server markup, hook components, element templates, and the case where the server element ends before the hole (still rebuilds and reports).Reviewed by Cursor Bugbot for commit 96422d7. Bugbot is set up for automated code reviews on this repo. Configure here.