Skip to content

fix(hydration): adopt an unframed fragment component and continue after its last root - #1597

Merged
trueadm merged 13 commits into
mainfrom
fix/unframed-fragment-root
Oct 2, 2026
Merged

trueadm merged 13 commits into
mainfrom
fix/unframed-fragment-root

Conversation

@trueadm

@trueadm trueadm commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

When hydration finds a component call's server content without the call's own range (the server rendered a different @if arm with the same markup inline), a component whose template has several roots now adopts those server nodes and hydration continues after its last root. The next call adopts its own server range. This extends #1567's renderInPlace, which already handles single-root templates, to fragment templates, in both the development and the production compile.

Repro (server renders the first arm, client the second):

function A() @{ <b>{'a'}</b> }
function F() @{ <><s>{'s'}</s><i>{'i'}</i></> }
export function FX(props: { server?: boolean }) @{
	<div>
		@if (props.server) { <><s>{'s'}</s><i>{'i'}</i><A /></> } @else { <><F /><A /></> }
	</div>
}

Before:

  • Development compile (F goes through the lite slot): F's clone adopted a virtual fragment at <s> but left the cursor there. A then read <s> as its own root, reported a mismatch and rebuilt itself.
  • Production compile (F goes through componentSlotImpl's missing-range path, renderUnframed): F was always rebuilt and reported as a mismatch, even though the server nodes matched. Before fix(hydration): keep a later sibling's server range when a component without one is built #1589, the rebuild also swept A's server range.

After, in both compiles, F keeps <s> and <i>, A keeps its server <b>, and nothing is reported.

Changes

All in packages/octane/src/runtime.ts:

  • adopt(): a fragment template cloned at the node a call renders in place of (inPlace) now compares every root (fragmentRemainder) and records where its server nodes end (inPlaceEnd). A single-root template records the node after its root. renderInPlace moves the cursor there instead of past the first root.
  • renderUnframed: when an anchored call's fresh markers stand before a server element or text, which is where unframedBefore puts them, the body renders in place of that node through renderInPlace(..., unframed = true), with hydration active.
    • A template that matches is adopted, and the fresh end marker moves after the adopted nodes, framing them as the server's range would have.
    • A template that doesn't match is built fresh, with no report and no discard in adopt(). The existing report and discard then run after the body, so a seeded rejection still leaves the server's catch arm intact.
    • Bodies without a template at that node keep today's behavior: nested calls anchored at the fresh end marker still build on the client.
    • Appended calls (anchor === null, the fix(hydration): rebuild component calls in an adopted element with other server content #1563 path) and root-level calls whose root remainder is still unclaimed are unchanged.
  • Mismatches: the in-place walk stops at the enclosing range's close marker (fragmentRemainder(..., bounded)), because a hole's server form is never a close marker. An in-place fragment that does not match is rebuilt in both compiles: the lite path goes through rebuildFragment, the production path through renderUnframed.
  • Lite slots: renderLiteInPlace now records the cursor that renderInPlace left (parkInPlace), past a fragment's last root. The existing parkPast(root) stepped only past its first root.
  • renderBlock: its "fresh end marker means client-built" suspend now exempts that one frame (framesInPlace). This check runs only after isFresh is already true.
  • adopt() prologue: one pendingClaims flag replaces the rootRemainder === undefined test. The in-place checks sit behind that flag, so a framed clone does no more work than on main. fix(hydration): continue after a component adopted in place without a range #1567's single-root cursor === this.inPlace compare is now behind the flag too.

Validation

  • pnpm format:check: not run repo-wide. pnpm format:files:check passes on every changed file.
  • pnpm typecheck: not run repo-wide. pnpm typecheck:files passes on runtime.ts, the test, and the .tsrx fixture.
  • pnpm test: not run in full; local runs are being kept small because of machine load.
  • targeted tests: new packages/octane/tests/hydration/unframed-fragment-root.test.ts (dev and prod compile), covering a fragment of static roots and a fragment whose last root is a component. Each case asserts final markup, that every server node is the same node after hydration, no recoverable errors, and no dev warnings. A third case unmounts the adopted fragment by flipping the arm and back.

Bundle size: the signal-free budget gate passes (node benchmarks/bundle-size/run-minimal.mjs --budgets root-static-local root-chained-jsx hooks-state prop-attributes context; root-chained-jsx is 86,002 raw against its 86,016 budget). renderBlock ships in every bundle, so its isFresh(end) call became one rebuilds(end) call, which costs 1 byte there. The rest is in HydrationCapability, which only bundles that hydrate include. Hydration timing benchmarks were not measured: the machine's load average was around 50, so timings were not trustworthy.

Risk / follow-ups

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
Touches core hydration adoption, cursor advancement, and production unframed rendering; behavior changes from rebuild+mismatch to silent adoption when multi-root templates match server inline markup.

Overview
Fixes hydration when a component has no server range (e.g. another @if arm inlined the same DOM) but the client renders it as a multi-root fragment.

renderInPlace / adopt() now walk every fragment root against server siblings, record where adoption ends (inPlaceEnd), and advance the cursor after the last root instead of after the first—so the following component keeps its own range. A pendingClaims gate keeps the common clone path cheap.

renderUnframed (production missing-range path) can run the body in place when fresh markers sit directly before matching server element/text: successful adoption reframes those nodes; non-matching templates rebuild without an early discard so rejections still see the server catch arm. renderBlock uses new rebuilds() so that in-place frame is not treated as a client-only rebuild.

Lite slots call parkInPlace after in-place adoption so arm tail tracking matches the updated cursor.

Adds hydration tests (dev + prod compile) and an octane patch changeset.

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

trueadm and others added 8 commits October 2, 2026 15:12
… range

A component call that finds no server range of its own, because the server
rendered another @if/@switch arm there, adopts the server element at the
cursor in place. Neither componentSlotImpl's singleRoot path nor
componentSlotLite's no-range branch moved the cursor past that element, so
the next component adopted the same element again and the server's range
for it stayed on the page. When the first component's holes left the cursor
inside the element, the next call claimed the enclosing block's range and
discarded the arm.

HydrationCapability.renderInPlace renders such a call while adopt() watches
for its template adopting the node, then steps the cursor past it. The
singleRoot path stamps the cursor as the block boundary only when the body
adopted it (or threw), so a root rebuilt at a close marker no longer takes
that marker as its own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rwin-50350d

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

# Conflicts:
#	packages/octane/src/runtime.ts
…ifier

The repository forbids skip/todo modifiers in committed tests, so the
development-compile-only case moves into its own describe instead of
`it.runIf(dev)`. Only the development compile renders that hookless call
through the lite slot.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A component call that finds no server range of its own, because the
server rendered another @if arm inline there, renders in place of the
server node at the cursor (renderInPlace). A template with several roots
now compares every root there (fragmentRemainder) and, when they match,
adopts them and moves the cursor past the last one, so the next call
adopts its own server range.

- Development compile (lite slot): the next call no longer reads the
  fragment's first root, removes it, and renders itself twice.
- Production compile (renderUnframed): the body now renders in place of
  an element or text node. A matching template is adopted and framed by
  the fresh markers. A template that does not match is rebuilt without
  discarding anything until the body has run, so a seeded rejection still
  leaves the server catch arm intact. The stale sweep no longer removes a
  later sibling's server range or leaves its close marker behind.
- adopt() tests one `claiming` flag on its common path in place of the
  root-remainder check, so the in-place claims add no work to framed
  clones.

Stacked on #1567 (renderInPlace).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…' into fix/unframed-fragment-root

# Conflicts:
#	packages/octane/src/runtime.ts
…-root

# Conflicts:
#	packages/octane/src/runtime.ts
@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
@github-actions
github-actions Bot marked this pull request as draft October 2, 2026 19:02
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 31 value(s) increased
  • 🔴 bundle-reachability: 55 value(s) increased

Compares 3ec43daa4 with 4c3cdffa7 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 3.64 3.99 +9.6% ±29% ⚪ within noise
octane-tsrx replace 8.78 8.85 +0.8% ±15% ⚪ within noise
octane-tsrx add 3.87 3.97 +2.6% ±25% ⚪ within noise
octane-tsrx update 0.52 0.48 −7.7% ±55% ⚪ within noise
octane-tsrx select 0.27 0.17 −37.0% ±78% ⚪ within noise
octane-tsrx swap 0.43 0.45 +4.7% ±41% ⚪ within noise
octane-tsrx remove 0.53 0.44 −17.0% ±55% ⚪ within noise
octane-tsrx runlots 35.37 36.29 +2.6% ±32% ⚪ within noise
octane-tsrx select_lots 0.27 0.28 +3.7% ±47% ⚪ within noise
octane-tsrx clear 49.09 50.72 +3.3% ±10% ⚪ within noise
octane-jsx run 3.90 4.48 +14.9% ±28% ⚪ within noise
octane-jsx replace 9.00 9.61 +6.8% ±22% ⚪ within noise
octane-jsx add 3.46 3.53 +2.0% ±31% ⚪ within noise
octane-jsx update 0.68 0.61 −10.3% ±30% ⚪ within noise
octane-jsx select 0.43 0.45 +4.7% ±44% ⚪ within noise
octane-jsx swap 0.80 0.78 −2.5% ±35% ⚪ within noise
octane-jsx remove 0.63 0.86 +36.5% ±61% ⚪ within noise
octane-jsx runlots 32.12 32.80 +2.1% ±20% ⚪ within noise
octane-jsx select_lots 2.76 3.05 +10.5% ±35% ⚪ within noise
octane-jsx clear 50.28 52.40 +4.2% ±15% ⚪ within noise

Application bundle size (bytes)

target metric base head Δ
octane-tsrx js_raw 126,863 126,864 +1 (+0.0%) 🔴
octane-tsrx js_gzip 41,967 41,971 +4 (+0.0%) 🔴
octane-tsrx js_brotli 36,957 36,974 +17 (+0.0%) 🔴
octane-tsrx app_gzip 2,563 2,564 +1 (+0.0%) 🔴
octane-tsrx app_brotli 2,226 2,227 +1 (+0.0%) 🔴
octane-tsrx fw_raw 119,351 119,352 +1 (+0.0%) 🔴
octane-tsrx fw_gzip 39,404 39,407 +3 (+0.0%) 🔴
octane-tsrx fw_brotli 34,731 34,747 +16 (+0.0%) 🔴
octane-tsrx todo_js_raw 141,842 141,843 +1 (+0.0%) 🔴
octane-tsrx todo_js_gzip 46,829 46,832 +3 (+0.0%) 🔴
octane-tsrx todo_js_brotli 41,092 41,028 −64 (−0.2%) 🟢
octane-tsrx todo_app_brotli 2,121 2,119 −2 (−0.1%) 🟢
octane-tsrx todo_fw_raw 136,732 136,733 +1 (+0.0%) 🔴
octane-tsrx todo_fw_gzip 44,353 44,356 +3 (+0.0%) 🔴
octane-tsrx todo_fw_brotli 38,971 38,909 −62 (−0.2%) 🟢
octane-tsrx chat_js_raw 141,051 141,052 +1 (+0.0%) 🔴
octane-tsrx chat_js_gzip 46,781 46,784 +3 (+0.0%) 🔴
octane-tsrx chat_js_brotli 41,136 41,082 −54 (−0.1%) 🟢
octane-tsrx chat_app_gzip 2,979 2,978 −1 (−0.0%) 🟢
octane-tsrx chat_app_brotli 2,627 2,634 +7 (+0.3%) 🔴
octane-tsrx chat_fw_raw 134,398 134,399 +1 (+0.0%) 🔴
octane-tsrx chat_fw_gzip 43,802 43,806 +4 (+0.0%) 🔴
octane-tsrx chat_fw_brotli 38,509 38,448 −61 (−0.2%) 🟢
octane-tsrx weather_js_raw 178,001 178,002 +1 (+0.0%) 🔴
octane-tsrx weather_js_gzip 58,195 58,198 +3 (+0.0%) 🔴
octane-tsrx weather_js_brotli 50,613 50,633 +20 (+0.0%) 🔴
octane-tsrx weather_app_brotli 7,578 7,582 +4 (+0.1%) 🔴
octane-tsrx weather_fw_raw 151,266 151,267 +1 (+0.0%) 🔴
octane-tsrx weather_fw_gzip 49,150 49,153 +3 (+0.0%) 🔴
octane-tsrx weather_fw_brotli 43,035 43,051 +16 (+0.0%) 🔴
octane-jsx js_raw 226,534 226,535 +1 (+0.0%) 🔴
octane-jsx js_gzip 72,280 72,284 +4 (+0.0%) 🔴
octane-jsx js_brotli 62,530 62,578 +48 (+0.1%) 🔴
octane-jsx app_brotli 2,497 2,520 +23 (+0.9%) 🔴
octane-jsx fw_raw 218,067 218,068 +1 (+0.0%) 🔴
octane-jsx fw_gzip 69,336 69,340 +4 (+0.0%) 🔴
octane-jsx fw_brotli 60,033 60,058 +25 (+0.0%) 🔴

8 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
cli-spa-starter raw 116,555 116,556 +1 (+0.0%) 🔴
cli-spa-starter gzip 39,345 39,347 +2 (+0.0%) 🔴
cli-spa-starter brotli 34,351 34,393 +42 (+0.1%) 🔴
root-static-specialized raw 77,086 77,087 +1 (+0.0%) 🔴
root-static-specialized gzip 25,585 25,584 −1 (−0.0%) 🟢
root-static-specialized brotli 22,774 22,770 −4 (−0.0%) 🟢
root-chained-jsx raw 86,001 86,002 +1 (+0.0%) 🔴
root-chained-jsx gzip 28,540 28,544 +4 (+0.0%) 🔴
root-chained-jsx brotli 25,331 25,337 +6 (+0.0%) 🔴
root-static raw 202,854 202,855 +1 (+0.0%) 🔴
root-static gzip 64,487 64,490 +3 (+0.0%) 🔴
root-static brotli 55,913 55,887 −26 (−0.0%) 🟢
root-static-local raw 77,089 77,090 +1 (+0.0%) 🔴
root-static-local gzip 25,572 25,571 −1 (−0.0%) 🟢
root-static-local brotli 22,773 22,779 +6 (+0.0%) 🔴
hooks-state raw 89,250 89,251 +1 (+0.0%) 🔴
hooks-state brotli 26,396 26,350 −46 (−0.2%) 🟢
prop-attributes raw 97,453 97,454 +1 (+0.0%) 🔴
prop-attributes gzip 32,394 32,397 +3 (+0.0%) 🔴
prop-attributes brotli 28,683 28,719 +36 (+0.1%) 🔴
context raw 110,689 110,690 +1 (+0.0%) 🔴
context gzip 36,668 36,671 +3 (+0.0%) 🔴
context brotli 32,470 32,446 −24 (−0.1%) 🟢
hydrate-root raw 167,251 168,363 +1,112 (+0.7%) 🔴
hydrate-root gzip 53,308 53,583 +275 (+0.5%) 🔴
hydrate-root brotli 46,419 46,647 +228 (+0.5%) 🔴
deferred-hydration raw 230,392 231,504 +1,112 (+0.5%) 🔴
deferred-hydration gzip 73,105 73,392 +287 (+0.4%) 🔴
deferred-hydration brotli 63,041 63,261 +220 (+0.3%) 🔴
suspense-transition raw 167,220 167,221 +1 (+0.0%) 🔴
suspense-transition gzip 53,743 53,746 +3 (+0.0%) 🔴
suspense-transition brotli 46,939 47,004 +65 (+0.1%) 🔴
component-owned-effects raw 81,698 81,699 +1 (+0.0%) 🔴
component-owned-effects gzip 26,940 26,938 −2 (−0.0%) 🟢
component-owned-effects brotli 23,980 23,984 +4 (+0.0%) 🔴
binding-hooks raw 87,763 87,764 +1 (+0.0%) 🔴
binding-hooks gzip 29,343 29,342 −1 (−0.0%) 🟢
binding-hooks brotli 26,104 26,174 +70 (+0.3%) 🔴
binding-base-ui-vite raw 213,045 213,046 +1 (+0.0%) 🔴
binding-base-ui-vite gzip 68,059 68,065 +6 (+0.0%) 🔴
binding-base-ui-vite brotli 59,041 59,085 +44 (+0.1%) 🔴
binding-base-ui-esbuild raw 211,004 211,005 +1 (+0.0%) 🔴
binding-base-ui-esbuild gzip 68,038 68,042 +4 (+0.0%) 🔴
binding-base-ui-esbuild brotli 59,014 58,973 −41 (−0.1%) 🟢
binding-aria-esbuild gzip 3,363 3,361 −2 (−0.1%) 🟢
binding-radix-vite raw 214,975 214,976 +1 (+0.0%) 🔴
binding-radix-vite gzip 68,623 68,628 +5 (+0.0%) 🔴
binding-radix-vite brotli 59,498 59,549 +51 (+0.1%) 🔴
binding-radix-esbuild raw 212,894 212,895 +1 (+0.0%) 🔴
binding-radix-esbuild gzip 68,614 68,618 +4 (+0.0%) 🔴
binding-radix-esbuild brotli 59,485 59,473 −12 (−0.0%) 🟢
binding-mantine-hooks-vite raw 98,088 98,089 +1 (+0.0%) 🔴
binding-mantine-hooks-vite gzip 32,609 32,613 +4 (+0.0%) 🔴
binding-mantine-hooks-vite brotli 28,963 28,975 +12 (+0.0%) 🔴
binding-mantine-hooks-esbuild raw 97,678 97,679 +1 (+0.0%) 🔴
binding-mantine-hooks-esbuild gzip 32,788 32,789 +1 (+0.0%) 🔴
binding-mantine-hooks-esbuild brotli 29,107 29,100 −7 (−0.0%) 🟢
binding-apollo-client-vite raw 358,100 358,101 +1 (+0.0%) 🔴
binding-apollo-client-vite gzip 112,190 112,193 +3 (+0.0%) 🔴
binding-apollo-client-vite brotli 97,843 97,909 +66 (+0.1%) 🔴
binding-apollo-client-esbuild raw 361,051 361,052 +1 (+0.0%) 🔴
binding-apollo-client-esbuild gzip 114,404 114,406 +2 (+0.0%) 🔴
binding-apollo-client-esbuild brotli 99,665 99,551 −114 (−0.1%) 🟢
binding-usehooks-ts-vite raw 98,721 98,722 +1 (+0.0%) 🔴
binding-usehooks-ts-vite gzip 32,768 32,772 +4 (+0.0%) 🔴
binding-usehooks-ts-vite brotli 29,118 29,120 +2 (+0.0%) 🔴
binding-usehooks-ts-esbuild raw 98,300 98,301 +1 (+0.0%) 🔴
binding-usehooks-ts-esbuild gzip 32,933 32,937 +4 (+0.0%) 🔴
binding-usehooks-ts-esbuild brotli 29,275 29,270 −5 (−0.0%) 🟢

36 other measured values are unchanged.

trueadm and others added 2 commits October 2, 2026 20:35
…-root

# Conflicts:
#	packages/octane/src/runtime.ts
…on call

renderBlock ships in every bundle, so the second call it made for the
fresh-frame exemption pushed root-chained-jsx 2 bytes over its committed
budget. HydrationCapability.rebuilds(end) now answers both questions at
the one call site isFresh(end) used to fill.

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

# Conflicts:
#	packages/octane/src/runtime.ts

@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: Hole can escape enclosing range
    • Added an isBlockClose guard in fragmentRemainder so that when a comment hole's server content is missing and actual sits on the enclosing range's close marker, sibling() is not called and the remainder stays on the close instead of escaping past it.

Create PR

Or push these changes by commenting:

@cursor push 03dd48ca02
Preview (03dd48ca02)
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
@@ -20165,7 +20165,9 @@
 			) {
 				return undefined;
 			}
-			actual = this.sibling(actual, 1);
+			// A block close is the enclosing range's boundary. A comment hole whose
+			// server content is missing lands here; do not walk past it.
+			if (!isBlockClose(actual)) actual = this.sibling(actual, 1);
 			expected = getNextSibling(expected);
 			childIndex++;
 		}

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

Reviewed by Cursor Bugbot for commit b79077b. Configure here.

Comment thread packages/octane/src/runtime.ts Resolved
trueadm and others added 2 commits October 2, 2026 21:02
…ing range

A fragment template adopted in place of a server node compared its roots
against the server nodes after that node. A hole skips the shape check, so
when the server's range ended where a hole was expected, the walk stepped
past the range's close: the fragment matched, its end landed outside the
@if arm, and production moved the fresh end marker out of the arm.

The in-place walk now fails at the enclosing range's close. A fragment that
does not match where it stands is rebuilt in both compiles: the lite path
rebuilds it at once (rebuildFragment) instead of adopting its first root,
whose holes then claimed the wrong server nodes.

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

# Conflicts:
#	packages/octane/src/runtime.ts
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