Repository navigation
Conversation
… 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]>
Benchmark report
Compares js-framework: 1k/10k row operations (ms, lower is better)All 20 timed operations (20 within noise)
Application bundle size (bytes)
21 other measured values are unchanged. Public-import reachability bundles (bytes)
98 other measured values are unchanged. CI job durations
Compares the CI run for
All 26 timed jobs
|
There was a problem hiding this comment.
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;afterremoveRange(from, end);inrenderClaimedto park the hydration cursor on the live end marker, matching whatdiscard()already does after the same kind of removal.
- Added
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.
…opted-branch-tail # Conflicts: # packages/octane/src/runtime.ts
… 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]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
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.
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.
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]>
|
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 |
…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]>


Summary
When the server rendered another arm of an
@ifor@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 noonRecoverableErrorand no dev diagnostic: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.
renderBranchSlothydrates an adopted arm throughHydrationCapability.renderClaimed. It removes what the server left after the arm's content, then reports once: error 337 throughonRecoverableError, 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.claimRootsbefore any hole renders. It costs one pointer compare inadopt()(cursor === this.claimFrom) and nothing else on the adoption path.template()'s existingfragargument instead of1. It also no longer pre-wraps fixed-HTML multi-root templates in<octane-frag>withfrag=0, which would carry no count. Every multi-root template ships raw markup, as resolved-HTML and foreign ones already did, andparseTemplateadds 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.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-tailtest 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:checkon every changed file passes)pnpm typecheck(not run repo-wide;pnpm typecheck:fileson every changed.ts/.js/.tsrxfile, fixtures passed explicitly, passes)pnpm test(the root run was not used; theoctaneandoctane-prodVitest projects were run in full before the rebase onto main, see below)tests/hydration/adopted-branch-tail.test.tsruns 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.frag=1. That last one makes production delete adopted roots and report a tail on a clean arm.tests/compiler/template-root-count.test.tschecks 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.tscomes from fix(hydration): discard server ranges a shorter @if/@switch arm leaves unclaimed #1564.packages/octane/tests/hydration,packages/octane/tests/compilerandrecoverable-callback.test.tsinoctaneandoctane-prod. Two load-timeout failures (native-condition-demand,hydration-ssr-diagnostics) pass in isolation.octaneandoctane-prodprojects passed exceptbehavior-root.test.tstimeouts 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 syncleaves the tree clean (it adds code 337 to the CLI data).pnpm error-codes:checkpasses.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@ifgrow by 32 raw / 12–18 gzip bytes. That is therenderClaimedcall site inrenderBranchSlot(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.newshydrate fixture has no@if, so it would exercise only the added compare inadopt().Risk / follow-ups
ForeignListBranch: a stale server list ahead of a rebuilt<i>. fix(hydration): discard server ranges a shorter @if/@switch arm leaves unclaimed #1564 removes it by stopping at the first client-built node; this PR leaves the whole tail. It overlaps fix(hydration): keep a rebuilt clone where the server node it replaced stood #1561.ForeignNodeBranch: a stale<s>after a rebuilt clone.The goofy-bhaskara draft records where a top-level unframed component's root ends in the same way this PR does for the arm's own template, and stops at the first client-built node. Whichever arm-tail PR lands should cover these cases.
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.@trybodies and@foritems show it only when server and client sources differ. A separate session is extending this mechanism to component frames.renderBranchSlot's adopted-arm branch, so whichever lands second needs a small merge.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 adoption for
@if/@switchand the multi-roottemplate()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/@switcharm 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 viaonRecoverableError(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 existingfragargument (replacing compile-time<octane-frag>wrapping andfrag=1).claimRootsrecords the boundary when the arm's template adopts the range's first node.Inspect output gains
ns/fragon 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.