Skip to content

fix(hydration): discard the server content an adopted @if/@switch arm leaves unclaimed - #1565

Closed
trueadm wants to merge 4 commits into
mainfrom
fix/adopted-branch-tail
Closed

trueadm wants to merge 4 commits into
mainfrom
fix/adopted-branch-tail

Conversation

@trueadm

@trueadm trueadm commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

When the server rendered another arm of an @if or @switch, the client arm adopts the server's arm range from its start: the arm markers do not record which arm the server rendered. If the client arm's content is a prefix of the server's, hydration adopted that prefix and left the rest on screen, with no onRecoverableError and no dev diagnostic:

function Leaf() @{ <i>{label() as string}</i> }
export function AdoptedTail(props: { server?: boolean }) @{
	<div>
		@if (props.server) { <><Leaf /><s class="foreign">{'f'}</s></> } @else { <Leaf /> }
	</div>
}

The server renders { server: true } and the client hydrates {}. The final DOM kept <s class="foreign">f</s> after <i>ok</i> in both dev and prod.

Fix. renderBranchSlot hydrates an adopted arm through HydrationCapability.renderClaimed. It removes what the server left after the arm's content, then reports once: error 337 through onRecoverableError, plus a located dev warning ("the client expected the end of the branch but the server rendered <s>"). The nodes the arm adopted keep their identity.

The hard part is knowing where the arm's content ends. clone() leaves the hydration cursor parked on an adopted root, so "cursor !== end" does not mean there is a tail. A fragment's trailing static roots are referenced by nothing after mount.

  • The arm's own template, or a component inheriting the arm's range, records where its roots end when it adopts the range's first node. This happens in claimRoots before any hole renders. It costs one pointer compare in adopt() (cursor === this.claimFrom) and nothing else on the adoption path.
  • A fragment template steps its root count logically. Dev reads the count from the parsed template. Production must not parse templates during hydration, so the compiler now passes a multi-root template's root count as template()'s existing frag argument instead of 1. It also no longer pre-wraps fixed-HTML multi-root templates in <octane-frag> with frag=0, which would carry no count. Every multi-root template ships raw markup, as resolved-HTML and foreign ones already did, and parseTemplate adds the same wrapper when it parses. An arm in a helper passed as a render prop is covered by a production-runtime no-parse test.
  • A template-less arm (only components or nested blocks) ends where its last slot's own range ends, which must agree with the cursor. A component that adopted a server node without its frame parks the cursor there, so that case is left alone.
  • Nothing is removed if the tail holds client-built nodes or the range cannot be confirmed.

This supersedes #1564. That PR discards only tails that start with a server range, and leaves element and text tails (the case above) for a follow-up. Its branch-arm-tail test file and fixture are included here unchanged, except that the arm-discard reports match code 337 instead of 51. Every case passes on this branch in both test projects. #1564 also discards a list left after a rebuilt clone; that case belongs with #1561, which sweeps a rebuilt clone's tail.

Validation

  • pnpm format:check (not run repo-wide; pnpm format:files:check on every changed file passes)
  • pnpm typecheck (not run repo-wide; pnpm typecheck:files on every changed .ts/.js/.tsrx file, fixtures passed explicitly, passes)
  • pnpm test (the root run was not used; the octane and octane-prod Vitest projects were run in full before the rebase onto main, see below)
  • targeted tests:
    • tests/hydration/adopted-branch-tail.test.ts runs three modes: dev compile, prod compile, and prod compile with a production runtime (vi.stubEnv('NODE_ENV', 'production')). It covers a sole component, a single root, a static fragment whose tail ends with the client's last tag, a fragment ending with a component, @switch, inner and outer nested arms, a clean arm (no report, and no template parse in production), and a server node a component adopted without its frame (kept). All 12 tail cases fail on main.
    • Mutation checks turn the suite red for each piece: dropping the last-slot check, forcing a root count of 1, removing the claim save/restore, and reverting the compiler to frag=1. That last one makes production delete adopted roots and report a tail on a clean arm.
    • tests/compiler/template-root-count.test.ts checks that the emitted root count equals the parsed root count for every multi-root template in the fixture corpus (over 100).
    • tests/hydration/branch-arm-tail.test.ts comes from fix(hydration): discard server ranges a shorter @if/@switch arm leaves unclaimed #1564.
    • After the rebase: packages/octane/tests/hydration, packages/octane/tests/compiler and recoverable-callback.test.ts in octane and octane-prod. Two load-timeout failures (native-condition-demand, hydration-ssr-diagnostics) pass in isolation.
    • Before the rebase, the full octane and octane-prod projects passed except behavior-root.test.ts timeouts under a machine load average of about 60. Main fails that file the same way under the same load, and it passes 207/207 in isolation.
    • pnpm sync leaves the tree clean (it adds code 337 to the CLI data). pnpm error-codes:check passes.
  • Bundle size (node benchmarks/bundle-size/run-minimal.mjs, vs main): hydrate-root +1,136 raw / +388 gzip, deferred-hydration +1,137 / +361. Client-only applications that use @if grow by 32 raw / 12–18 gzip bytes. That is the renderClaimed call site in renderBranchSlot (the PR bench's todo, chat and weather apps); the method body is dropped from client-only bundles. The minimal client-only scenarios are unchanged, and three binding bundles move by a few bytes of compression noise.
  • No timing benchmark: the news hydrate fixture has no @if, so it would exercise only the added compare in adopt().

Risk / follow-ups

  • Tails this PR leaves in place (found by the goofy-bhaskara session; fix(hydration): discard server ranges a shorter @if/@switch arm leaves unclaimed #1564 or that draft removes them). All four come from this PR's conservative rule: when a component adopted a server node without its frame, or a recovery rebuilt nodes in the tail, the tail stays.
  • The same gap exists for component frames whose identity differs between server and client (const C = cond ? A : B, {cond ? <A/> : <B/>}) and for conditional returns (the return slot's lent range). These are reachable from the same source. @try bodies and @for items show it only when server and client sources differ. A separate session is extending this mechanism to component frames.
  • An unframed component adoption parks the cursor, so the next appended component mis-adopts the same node. This is pre-existing and is being fixed separately.
  • fix(hydration): keep a rebuilt clone where the server node it replaced stood #1561 also edits renderBranchSlot's adopted-arm branch, so whichever lands second needs a small merge.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Medium Risk
Changes core hydration adoption for @if/@switch and the multi-root template() ABI; incorrect root counts could remove adopted nodes or leave stale DOM, though the new test suite targets both paths.

Overview
Fixes a hydration bug where the client adopted the prefix of a server @if/@switch arm but left extra server markup on screen with no error when the two sides picked different arms.

Hydration now runs adopted arms through renderClaimed, which finds where the client arm's content ends, removes any unclaimed server nodes before the branch end marker, and reports once via onRecoverableError (new client error #337) plus a located dev warning. Adopted nodes keep their identity.

Finding the end of multi-root arm content in production without parsing templates drives a compiler/runtime contract change: multi-root templates ship raw markup and pass the actual root count into template()'s existing frag argument (replacing compile-time <octane-frag> wrapping and frag=1). claimRoots records the boundary when the arm's template adopts the range's first node.

Inspect output gains ns / frag on templates; tests cover tail removal, root-count accuracy, and the prior branch-arm-tail scenarios (now reporting #337).

Reviewed by Cursor Bugbot for commit e139108. Bugbot is set up for automated code reviews on this repo. Configure here.

… leaves unclaimed

When the server rendered another arm of an @if or @switch, the client arm
adopts the server's arm range from its start. A client arm whose content is
a prefix of the server's adopted that prefix and left the rest on screen
with no report.

renderBranchSlot now hydrates an adopted arm through
HydrationCapability.renderClaimed, which removes what the server left after
the arm's content and reports it once (new error 337) with a dev diagnostic
at the directive. The arm's own template records where its roots end when it
adopts the range's first node: one pointer compare in adopt(), and the walk
runs before any hole renders. A template-less arm ends where its last slot's
own range ends, and must agree with the cursor; a slot that adopted a server
node without its range parks the cursor there, so that case is left alone,
as is any tail holding client-built nodes.

A fragment's trailing static roots are referenced by nothing after mount, so
the compiler now passes a raw multi-root template's root count as
template()'s frag argument (previously 1). Production hydration reads it
instead of parsing the template.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Oct 2, 2026
@trueadm
trueadm marked this pull request as ready for review October 2, 2026 13:30
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 16 value(s) increased
  • 🔴 bundle-reachability: 6 value(s) increased

Compares 15c7b97a2 with dc0a69553 on the same runner. Timing verdicts require a change beyond the combined margin of error (at least 5%) and one 0.1ms timer tick, with the fastest sample also moving beyond that margin. Workflow run

js-framework: 1k/10k row operations (ms, lower is better)

All 20 timed operations (20 within noise)
target operation base head Δ noise
octane-tsrx run 4.02 4.15 +3.2% ±9% ⚪ within noise
octane-tsrx replace 8.78 9.45 +7.6% ±21% ⚪ within noise
octane-tsrx add 3.92 3.92 −0.0% ±16% ⚪ within noise
octane-tsrx update 0.47 0.47 +0.0% ±49% ⚪ within noise
octane-tsrx select 0.22 0.24 +9.1% ±64% ⚪ within noise
octane-tsrx swap 0.42 0.56 +33.3% ±49% ⚪ within noise
octane-tsrx remove 0.44 0.60 +36.4% ±47% ⚪ within noise
octane-tsrx runlots 34.38 36.65 +6.6% ±21% ⚪ within noise
octane-tsrx select_lots 0.32 0.30 −6.3% ±26% ⚪ within noise
octane-tsrx clear 52.83 49.31 −6.7% ±12% ⚪ within noise
octane-jsx run 4.67 5.19 +11.1% ±37% ⚪ within noise
octane-jsx replace 9.27 10.55 +13.8% ±35% ⚪ within noise
octane-jsx add 3.74 3.73 −0.3% ±10% ⚪ within noise
octane-jsx update 0.76 0.81 +6.6% ±42% ⚪ within noise
octane-jsx select 0.59 0.65 +10.2% ±34% ⚪ within noise
octane-jsx swap 0.78 0.87 +11.5% ±39% ⚪ within noise
octane-jsx remove 0.86 0.76 −11.6% ±34% ⚪ within noise
octane-jsx runlots 33.31 36.67 +10.1% ±24% ⚪ within noise
octane-jsx select_lots 3.10 2.85 −8.1% ±52% ⚪ within noise
octane-jsx clear 51.38 53.93 +5.0% ±8% ⚪ within noise

Application bundle size (bytes)

target metric base head Δ
octane-tsrx todo_js_raw 141,134 141,166 +32 (+0.0%) 🔴
octane-tsrx todo_js_gzip 46,602 46,614 +12 (+0.0%) 🔴
octane-tsrx todo_js_brotli 40,811 40,839 +28 (+0.1%) 🔴
octane-tsrx todo_app_gzip 2,476 2,475 −1 (−0.0%) 🟢
octane-tsrx todo_app_brotli 2,117 2,118 +1 (+0.0%) 🔴
octane-tsrx todo_fw_raw 136,024 136,056 +32 (+0.0%) 🔴
octane-tsrx todo_fw_gzip 44,126 44,139 +13 (+0.0%) 🔴
octane-tsrx todo_fw_brotli 38,694 38,721 +27 (+0.1%) 🔴
octane-tsrx chat_js_raw 140,379 140,411 +32 (+0.0%) 🔴
octane-tsrx chat_js_gzip 46,545 46,557 +12 (+0.0%) 🔴
octane-tsrx chat_js_brotli 40,865 40,841 −24 (−0.1%) 🟢
octane-tsrx chat_app_gzip 2,978 2,976 −2 (−0.1%) 🟢
octane-tsrx chat_app_brotli 2,641 2,630 −11 (−0.4%) 🟢
octane-tsrx chat_fw_raw 133,726 133,758 +32 (+0.0%) 🔴
octane-tsrx chat_fw_gzip 43,567 43,581 +14 (+0.0%) 🔴
octane-tsrx chat_fw_brotli 38,224 38,211 −13 (−0.0%) 🟢
octane-tsrx weather_js_raw 176,620 176,652 +32 (+0.0%) 🔴
octane-tsrx weather_js_gzip 57,721 57,742 +21 (+0.0%) 🔴
octane-tsrx weather_js_brotli 50,194 50,125 −69 (−0.1%) 🟢
octane-tsrx weather_app_gzip 9,043 9,045 +2 (+0.0%) 🔴
octane-tsrx weather_app_brotli 7,603 7,581 −22 (−0.3%) 🟢
octane-tsrx weather_fw_raw 149,885 149,917 +32 (+0.0%) 🔴
octane-tsrx weather_fw_gzip 48,678 48,697 +19 (+0.0%) 🔴
octane-tsrx weather_fw_brotli 42,591 42,544 −47 (−0.1%) 🟢

21 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
hydrate-root raw 161,234 162,382 +1,148 (+0.7%) 🔴
hydrate-root gzip 51,677 52,025 +348 (+0.7%) 🔴
hydrate-root brotli 44,954 45,302 +348 (+0.8%) 🔴
deferred-hydration raw 223,608 224,757 +1,149 (+0.5%) 🔴
deferred-hydration gzip 71,134 71,501 +367 (+0.5%) 🔴
deferred-hydration brotli 61,405 61,701 +296 (+0.5%) 🔴
binding-radix-esbuild brotli 59,070 59,018 −52 (−0.1%) 🟢

98 other measured values are unchanged.

CI job durations

  • 🟡 5 job(s) slower than every recent main run: test shard (Node 24, 1/4), test shard (Node 24, 3/4), React parity shard (2/4), example apps (1/3), example apps (3/3)

Compares the CI run for 1e969db30 (run) with the last 5 successful main push runs. A job is only slower or faster outside the whole main range, by at least 10% and 15s. Job time excludes runner setup.

job main median main range this PR Δ
wall clock (first job start to last job end) 12m 39s 11m 55s–14m 51s 14m 04s +1m 25s (+11%) ⚪ within noise
total job time 140m 36s 134m 18s–146m 56s 149m 21s +8m 45s (+6%) ⚪ within noise
test shard (Node 24, 1/4) 11m 40s 11m 19s–12m 22s 13m 25s +1m 45s (+15%) 🟡 slower
test shard (Node 24, 3/4) 9m 31s 9m 24s–10m 09s 10m 58s +1m 27s (+15%) 🟡 slower
React parity shard (2/4) 10m 05s 9m 52s–11m 02s 11m 25s +1m 20s (+13%) 🟡 slower
example apps (1/3) 3m 13s 3m 04s–3m 14s 3m 34s +21s (+11%) 🟡 slower
example apps (3/3) 3m 30s 3m 22s–3m 41s 3m 51s +21s (+10%) 🟡 slower
All 26 timed jobs
job main median main range this PR Δ
heavy integration (browser - chromium) 11m 08s 10m 58s–14m 17s 13m 15s +2m 07s (+19%) ⚪ within noise
test shard (Node 24, 1/4) 11m 40s 11m 19s–12m 22s 13m 25s +1m 45s (+15%) 🟡 slower
test shard (Node 24, 3/4) 9m 31s 9m 24s–10m 09s 10m 58s +1m 27s (+15%) 🟡 slower
React parity shard (2/4) 10m 05s 9m 52s–11m 02s 11m 25s +1m 20s (+13%) 🟡 slower
lint checks 8m 01s 7m 43s–9m 15s 9m 04s +1m 03s (+13%) ⚪ within noise
React parity shard (3/4) 10m 25s 10m 07s–10m 59s 11m 22s +57s (+9%) ⚪ within noise
test shard (Node 24, 2/4) 11m 55s 10m 38s–12m 45s 12m 30s +35s (+5%) ⚪ within noise
test shard (Node 24, 4/4) 10m 26s 10m 21s–11m 11s 10m 56s +30s (+5%) ⚪ within noise
React parity shard (4/4) 10m 53s 10m 08s–11m 23s 11m 20s +27s (+4%) ⚪ within noise
example apps (1/3) 3m 13s 3m 04s–3m 14s 3m 34s +21s (+11%) 🟡 slower
example apps (3/3) 3m 30s 3m 22s–3m 41s 3m 51s +21s (+10%) 🟡 slower
validate publishable packages 3m 58s 3m 51s–4m 54s 4m 12s +14s (+6%) ⚪ within noise
heavy integration (package builds, eval corpus, runtime loaders, Astro) 5m 23s 5m 21s–5m 45s 5m 30s +7s (+2%) ⚪ within noise
typecheck checks 2m 01s 1m 56s–2m 40s 2m 07s +6s (+5%) ⚪ within noise
Lynx compatibility 1m 32s 1m 29s–1m 33s 1m 37s +5s (+5%) ⚪ within noise
React parity shard (1/4) 11m 04s 10m 23s–11m 19s 11m 08s +4s (+1%) ⚪ within noise
Three compatibility 2m 43s 2m 42s–2m 56s 2m 45s +2s (+1%) ⚪ within noise
classify changeset release 13s 12s–14s 14s +1s (+8%) ⚪ within noise
example apps (2/3) 3m 43s 3m 42s–3m 55s 3m 44s +1s (+0%) ⚪ within noise
typecheck 3s 3s–3s 3s ±0s (±0%) ⚪ within noise
examples 3s 3s–4s 3s ±0s (±0%) ⚪ within noise
lint 3s 3s–4s 3s ±0s (±0%) ⚪ within noise
test (24) 3s 2s–5s 3s ±0s (±0%) ⚪ within noise
CI provenance 3s 3s–4s 3s ±0s (±0%) ⚪ within noise
React parity checks 12s 10s–14s 11s −1s (−8%) ⚪ within noise
website integration suite 6m 06s 5m 43s–7m 00s 5m 58s −8s (−2%) ⚪ within noise

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Detached hydration cursor after tail discard
    • Added this.node = end; after removeRange(from, end); in renderClaimed to park the hydration cursor on the live end marker, matching what discard() already does after the same kind of removal.

Create PR

Or push these changes by commenting:

@cursor push 1b3b191ed1
Preview (1b3b191ed1)
diff --git a/packages/octane/src/runtime.ts b/packages/octane/src/runtime.ts
--- a/packages/octane/src/runtime.ts
+++ b/packages/octane/src/runtime.ts
@@ -19390,6 +19390,7 @@
 			}
 		}
 		removeRange(from, end);
+		this.node = end;
 	}
 
 	/**

You can send follow-ups to the cloud agent here.

Comment thread packages/octane/src/runtime.ts Resolved
trueadm and others added 2 commits October 2, 2026 14:41
… tail

renderClaimed removed the stale tail without moving the hydration cursor,
which could still point at a removed node. renderBranchSlot re-parks the
cursor past the slot right after, so nothing observed it, but discard()
already parks on the range end after the same kind of removal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: HTML arm templates parse during hydration
    • Encoded the root count as a negative frag value for pre-wrapped octane-frag templates so templateRootCount reads the count directly without parsing, and adjusted parseTemplate/lazyFragmentRootMatches to treat negative frag as already-wrapped.

Create PR

Or push these changes by commenting:

@cursor push 53af2cba09
Preview (53af2cba09)
diff --git a/packages/octane/src/compiler/compile.js b/packages/octane/src/compiler/compile.js
--- a/packages/octane/src/compiler/compile.js
+++ b/packages/octane/src/compiler/compile.js
@@ -26382,7 +26382,10 @@
 		const flag = nsFlag(tplNs);
 		// A raw multi-root template passes its root count, which hydration reads
 		// without parsing the template to find where the roots it adopted end.
-		const fragArg = !single && (flag !== 0 || resolvedFrag) ? htmlIdx : 0;
+		// Pre-wrapped HTML multi-root templates (flag=0, !resolvedFrag) store the
+		// count as a negative number so templateRootCount can read it without
+		// parsing and parseTemplate knows the wrapper is already present.
+		const fragArg = single ? 0 : flag !== 0 || resolvedFrag ? htmlIdx : -htmlIdx;
 		let template = rootTemplate;
 		if (!single && flag === 0 && !resolvedFrag) {
 			template = templateElement(

diff --git a/packages/octane/src/runtime.ts b/packages/octane/src/runtime.ts
--- a/packages/octane/src/runtime.ts
+++ b/packages/octane/src/runtime.ts
@@ -18388,7 +18388,9 @@
 	ns: 0 | 1 | 2 | 3;
 	/**
 	 * Raw multi-root markup: the number of roots, as the compiler counts them.
-	 * 0 = one root, or HTML roots pre-wrapped in `<octane-frag>`.
+	 * 0 = one root. Positive = raw fragment (SVG/MathML/opaque resolved-HTML),
+	 * parseTemplate adds the wrapper. Negative = HTML roots pre-wrapped in
+	 * `<octane-frag>`, count is the absolute value, wrapper already in `html`.
 	 */
 	frag: number;
 	parsed: Array<Node | null>;
@@ -18434,7 +18436,7 @@
 		// Fixed HTML multi-root templates arrive pre-wrapped by the compiler. Opaque
 		// multi-root templates carry raw markup because their eventual namespace is
 		// unknown, so add the equivalent wrapper only after HTML wins at clone time.
-		(STAGED_DOM?.view(t) ?? t).innerHTML = frag ? `<octane-frag>${html}</octane-frag>` : html;
+		(STAGED_DOM?.view(t) ?? t).innerHTML = frag > 0 ? `<octane-frag>${html}</octane-frag>` : html;
 		const root = getFirstChild(t.content) as Element;
 		// Multi-root HTML templates arrive wrapped in a synthetic <octane-frag>. The
 		// wrapper never exists in the server DOM (the roots render bare), so stamp it
@@ -18510,14 +18512,14 @@
 
 /**
  * How many roots a multi-root template has. The compiler passes the count as
- * a raw fragment's `frag`; a parsed or pre-wrapped template counts its
- * children.
+ * a raw fragment's `frag` (positive) or a pre-wrapped HTML fragment's `frag`
+ * (negative, absolute value = count); a parsed template counts its children.
  */
 function templateRootCount(template: Node | LazyTemplateRecord): number {
 	let parsed: Node;
 	if ((template as Node).nodeType === undefined) {
 		const lazy = template as LazyTemplateRecord;
-		if (lazy.frag !== 0) return lazy.frag;
+		if (lazy.frag !== 0) return lazy.frag > 0 ? lazy.frag : -lazy.frag;
 		parsed = resolveLazyTemplate(lazy);
 	} else parsed = template as Node;
 	let count = 0;
@@ -18554,7 +18556,7 @@
  */
 function lazyFragmentRootMatches(server: Node, lazy: LazyTemplateRecord): boolean {
 	const root =
-		lazy.frag !== 0
+		lazy.frag > 0
 			? lazyRootDescriptor(lazy)
 			: templateRootDescriptor(lazy.html, 13 /* '<octane-frag>'.length */);
 	if (root === 8) return true;

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit 1e969db. Configure here.

Comment thread packages/octane/src/runtime.ts Resolved
Fixed-HTML multi-root templates were still pre-wrapped in <octane-frag>
with frag=0, so they carried no root count. An @if arm in such a template,
as in a helper passed as a render prop, made production hydration parse the
template to find where the arm's roots end, a parse that cloneLazy
otherwise avoids. Every multi-root template now ships raw markup with its
root count, as resolved-HTML and foreign ones already did. parseTemplate
adds the same wrapper when it parses one, so the parsed DOM is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm

trueadm commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #1564 plus a follow-up PR from the goofy-bhaskara draft, which removes element and text tails and keeps error code 51. The follow-up takes this PR's compiler corpus test (emitted root count vs parsed roots across every fixture template) from the fix/adopted-branch-tail branch, which stays in place for that.

🤖 Generated with Claude Code

@trueadm trueadm closed this Oct 2, 2026
trueadm added a commit that referenced this pull request Oct 2, 2026
…witch arm leaves unclaimed (#1600)

* fix(hydration): discard the server elements and text a shorter @if/@switch arm leaves unclaimed

When the server rendered a longer @if or @switch arm, the client arm adopts
the start of the server's range. discardArmTail removes what follows a
range the arm claimed, but a template leaves the cursor on the elements and
text it adopts, so elements or text after the client arm's own roots stayed
on screen with no report. A component that adopted its root in place left
the same tail.

renderAdoptedArm now opens a claim on the arm's range, so the arm's own
template records where its roots end (claimRoots), and steps the cursor past
them as a range claim parks it. discardArmTail then removes the server
content from there, stops at client-built nodes, and reports code 51 once
with a dev diagnostic at the directive. A component that adopts its root in
place at the arm's top level parks the cursor past that root the same way
(parkPast), so the last such root records the arm's end too.

Production adoption never parses a template, so the compiler now ships
every multi-root template raw with its root count, as resolved-HTML and
foreign ones already did. A branch in a helper passed as a render prop, whose
template was pre-wrapped in <octane-frag> with no count, no longer parses it
in production. The compiler change and adopted-branch-tail.test.ts come from
the closed #1565.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(hydration): scope the arm tail record to a single in-place root

A component that adopts a fragment or text in place reports no adoption from
renderInPlace, so an arm that ends with one records no end and keeps the
server content after it, as before. Say so in renderAdoptedArm and the
changeset rather than claiming every in-place component.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant