Skip to content

fix(hydration): discard an arm's tail after a @try that rebuilt its arm - #1578

Merged
trueadm merged 3 commits into
mainfrom
fix/arm-tail-close-marker
Oct 2, 2026
Merged

trueadm merged 3 commits into
mainfrom
fix/arm-tail-close-marker

Conversation

@trueadm

@trueadm trueadm commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #1564, fixing the Cursor Bugbot finding left open when #1564 merged (review thread).

discardArmTail removes the server content that a shorter client @if/@switch arm leaves unclaimed. It looks for that content at the hydration cursor. Nested slots normally park the cursor past their range. A @try whose body throws on the client during hydration is the exception: it builds its catch arm fresh and rebuiltSlot parks the cursor on the boundary's close marker. When that boundary ends the client arm, discardArmTail saw a close marker rather than an open one and returned. The components the server's longer arm rendered after the boundary then stayed on screen, with no report.

@if (props.on) {
	<><Leaf v="x" />@try { <Boom /> } @catch (e) { <p>caught</p> }</>
} @else {
	<><Leaf v="x" />@try { <Boom /> } @catch (e) { <p>caught</p> }<Leaf v="z" /></>
}

The server renders { on: false } with Boom rendering fine. The client hydrates { on: true } with Boom throwing. Before this change the DOM ends <p>caught</p><em>z</em> and nothing is reported. After it, <em>z</em> is discarded with one structural onRecoverableError plus the development diagnostic "the client expected the end of the branch…".

Fix: a slot that parks the cursor on its close marker has claimed through that marker, so discardArmTail now looks one node past a close marker for the unclaimed range. Everything else is unchanged: an arm that claimed nothing is still left alone, as is a tail that starts with an element or text, and the discard still stops at client-built nodes.

Scope notes:

  • Bugbot's own description is broader than what reproduces. Nested @for (with and without items), nested @if (true and false), a nested @try that adopts or suspends, and a throwing @try wrapped in a component (alone or after a sibling) all already park past their close, and fix(hydration): discard server ranges a shorter @if/@switch arm leaves unclaimed #1564 handles them. I checked each shape.
  • Bugbot Autofix pushed cursor/close-marker-cursor-logic-eaaf with a loop over consecutive close markers and an IfTryThenTail test. That test passes on main without any fix, so it doesn't cover the failing path, and I couldn't construct a case that needs consecutive close markers. This PR keeps the single step and does not use that branch.

Validation

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 cursor logic in discardArmTail; scope is narrow (one branch when the cursor sits on a close marker) but incorrect behavior could affect DOM cleanup and mismatch reporting for @if/@switch arms ending in throwing @try boundaries.

Overview
Fixes a hydration gap when a shorter client @if/@switch arm ends with a @try whose body throws during hydration: the boundary rebuilds the catch arm and leaves the cursor on its close marker, so discardArmTail used to bail out and leave extra server-only nodes (e.g. a trailing <em>z</em>) with no recoverable error.

discardArmTail now advances one sibling past a close marker before scanning for unclaimed server content, then discards and reports a single structural onRecoverableError as before. Comments document the close-marker case.

Adds CaughtLast fixture and a hydration test that asserts the corrected DOM, one recoverable error, and the dev diagnostic. Patch changeset for octane.

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

A @Try whose body throws on the client during hydration builds its catch
arm fresh and parks the hydration cursor on its own close marker
(rebuiltSlot), not past it. When that boundary ends a shorter client
@if/@switch arm, discardArmTail found the close marker instead of the
server range after it and returned, so the components the server's
longer arm rendered after the boundary stayed on screen, unreported.

The slot that parked the cursor there claimed through its close marker,
so discardArmTail now looks one node past a close marker for the
unclaimed range. Reported by Cursor Bugbot on #1564.

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
@github-actions
github-actions Bot marked this pull request as draft October 2, 2026 15:33

@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: Single close step misses nested tails
    • Changed the single if (this.isClose(from)) to while (this.isClose(from) && from !== end) so that consecutive close markers from nested rebuilt slots are all skipped before the open-tail check.

Create PR

Or push these changes by commenting:

@cursor push 619671f5ae
Preview (619671f5ae)
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
@@ -19407,9 +19407,10 @@
 	 * Runs after a branch's first hydrating render, which adopted the server's
 	 * arm range from `first` to `end`. Every range the arm claims parks the
 	 * cursor past it, or on its close marker when the slot rebuilt its content
-	 * (a @try body that threw on the client), so once the arm has claimed
-	 * something, a server range at the cursor or just after that marker is one
-	 * that nothing in the arm claimed: the server rendered another arm here,
+	 * (a @try body that threw on the client — possibly nested, producing
+	 * consecutive close markers), so once the arm has claimed something, a
+	 * server range at the cursor or just past those markers is one that
+	 * nothing in the arm claimed: the server rendered another arm here,
 	 * longer than this one. Discard the server content from there up to `end`,
 	 * stopping at any client nodes that mismatch recovery built there, and
 	 * report it once.
@@ -19423,7 +19424,7 @@
 	discardArmTail(scope: Scope, slotKey: number, first: Node, end: Node): void {
 		let from = this.node;
 		if (from === first) return;
-		if (this.isClose(from)) from = getNextSibling(from);
+		while (this.isClose(from) && from !== end) from = getNextSibling(from);
 		if (!this.isOpen(from)) return;
 		let stop: Node | null = null;
 		let node: Node | null = from;

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

Reviewed by Cursor Bugbot for commit 379a2b9. Configure here.

Comment thread packages/octane/src/runtime.ts Resolved
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

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

Compares 2a8b39753 with f0ba08374 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.31 4.14 −3.9% ±22% ⚪ within noise
octane-tsrx replace 8.58 9.87 +15.0% ±59% ⚪ within noise
octane-tsrx add 4.09 4.04 −1.2% ±19% ⚪ within noise
octane-tsrx update 0.49 0.39 −20.4% ±57% ⚪ within noise
octane-tsrx select 0.18 0.17 −5.6% ±93% ⚪ within noise
octane-tsrx swap 0.42 0.32 −23.8% ±57% ⚪ within noise
octane-tsrx remove 0.36 0.33 −8.3% ±70% ⚪ within noise
octane-tsrx runlots 39.34 38.37 −2.5% ±31% ⚪ within noise
octane-tsrx select_lots 0.20 0.22 +10.0% ±64% ⚪ within noise
octane-tsrx clear 37.11 36.15 −2.6% ±21% ⚪ within noise
octane-jsx run 5.21 4.04 −22.5% ±44% ⚪ within noise
octane-jsx replace 8.28 7.77 −6.2% ±14% ⚪ within noise
octane-jsx add 3.78 4.49 +18.8% ±76% ⚪ within noise
octane-jsx update 0.62 0.55 −11.3% ±51% ⚪ within noise
octane-jsx select 0.35 0.35 −0.0% ±63% ⚪ within noise
octane-jsx swap 0.83 0.62 −25.3% ±47% ⚪ within noise
octane-jsx remove 0.59 0.51 −13.6% ±41% ⚪ within noise
octane-jsx runlots 34.58 35.97 +4.0% ±16% ⚪ within noise
octane-jsx select_lots 3.03 2.55 −15.8% ±29% ⚪ within noise
octane-jsx clear 38.11 34.50 −9.5% ±24% ⚪ within noise

Application bundle size (bytes)

target metric base head Δ
octane-tsrx todo_js_brotli 40,833 40,830 −3 (−0.0%) 🟢
octane-tsrx todo_app_brotli 2,123 2,120 −3 (−0.1%) 🟢
octane-tsrx weather_js_raw 176,859 176,889 +30 (+0.0%) 🔴
octane-tsrx weather_js_gzip 57,827 57,839 +12 (+0.0%) 🔴
octane-tsrx weather_js_brotli 50,265 50,251 −14 (−0.0%) 🟢
octane-tsrx weather_app_gzip 9,044 9,046 +2 (+0.0%) 🔴
octane-tsrx weather_app_brotli 7,562 7,575 +13 (+0.2%) 🔴
octane-tsrx weather_fw_raw 150,124 150,154 +30 (+0.0%) 🔴
octane-tsrx weather_fw_gzip 48,783 48,793 +10 (+0.0%) 🔴
octane-tsrx weather_fw_brotli 42,703 42,676 −27 (−0.1%) 🟢
octane-jsx js_raw 225,412 225,512 +100 (+0.0%) 🔴
octane-jsx js_gzip 71,924 71,994 +70 (+0.1%) 🔴
octane-jsx js_brotli 62,373 62,298 −75 (−0.1%) 🟢
octane-jsx app_gzip 2,944 2,943 −1 (−0.0%) 🟢
octane-jsx app_brotli 2,503 2,500 −3 (−0.1%) 🟢
octane-jsx fw_raw 216,945 217,045 +100 (+0.0%) 🔴
octane-jsx fw_gzip 68,980 69,051 +71 (+0.1%) 🔴
octane-jsx fw_brotli 59,870 59,798 −72 (−0.1%) 🟢

27 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
root-static raw 201,735 201,831 +96 (+0.0%) 🔴
root-static gzip 64,098 64,145 +47 (+0.1%) 🔴
root-static brotli 55,500 55,533 +33 (+0.1%) 🔴
context raw 110,113 110,155 +42 (+0.0%) 🔴
context gzip 36,436 36,441 +5 (+0.0%) 🔴
context brotli 32,240 32,286 +46 (+0.1%) 🔴
hydrate-root raw 162,049 163,412 +1,363 (+0.8%) 🔴
hydrate-root gzip 51,891 52,277 +386 (+0.7%) 🔴
hydrate-root brotli 45,171 45,513 +342 (+0.8%) 🔴
deferred-hydration raw 224,607 226,024 +1,417 (+0.6%) 🔴
deferred-hydration gzip 71,429 71,832 +403 (+0.6%) 🔴
deferred-hydration brotli 61,608 61,874 +266 (+0.4%) 🔴
suspense-transition raw 166,620 166,664 +44 (+0.0%) 🔴
suspense-transition gzip 53,542 53,544 +2 (+0.0%) 🔴
suspense-transition brotli 46,767 46,714 −53 (−0.1%) 🟢
binding-base-ui-vite raw 211,929 212,026 +97 (+0.0%) 🔴
binding-base-ui-vite gzip 67,683 67,761 +78 (+0.1%) 🔴
binding-base-ui-vite brotli 58,612 58,721 +109 (+0.2%) 🔴
binding-base-ui-esbuild raw 209,903 209,995 +92 (+0.0%) 🔴
binding-base-ui-esbuild gzip 67,624 67,699 +75 (+0.1%) 🔴
binding-base-ui-esbuild brotli 58,707 58,742 +35 (+0.1%) 🔴
binding-radix-vite raw 213,858 213,956 +98 (+0.0%) 🔴
binding-radix-vite gzip 68,245 68,281 +36 (+0.1%) 🔴
binding-radix-vite brotli 59,293 59,193 −100 (−0.2%) 🟢
binding-radix-esbuild raw 211,791 211,884 +93 (+0.0%) 🔴
binding-radix-esbuild gzip 68,206 68,296 +90 (+0.1%) 🔴
binding-radix-esbuild brotli 59,116 59,231 +115 (+0.2%) 🔴
binding-apollo-client-vite raw 356,980 357,073 +93 (+0.0%) 🔴
binding-apollo-client-vite gzip 111,795 111,840 +45 (+0.0%) 🔴
binding-apollo-client-vite brotli 97,503 97,523 +20 (+0.0%) 🔴
binding-apollo-client-esbuild raw 359,959 360,027 +68 (+0.0%) 🔴
binding-apollo-client-esbuild gzip 114,014 114,047 +33 (+0.0%) 🔴
binding-apollo-client-esbuild brotli 99,308 99,347 +39 (+0.0%) 🔴

72 other measured values are unchanged.

@trueadm
trueadm marked this pull request as ready for review October 2, 2026 15:52
…rker

# Conflicts:
#	packages/octane/src/runtime.ts
@trueadm
trueadm merged commit 52c9d33 into main Oct 2, 2026
31 checks passed
@trueadm
trueadm deleted the fix/arm-tail-close-marker branch October 2, 2026 16:18
trueadm added a commit that referenced this pull request Oct 3, 2026
…1621)

* fix(hydration): park past every boundary, list, and activity range

A @Try never moved the hydration cursor past its own server range, so a
following multi-root component in a template-less body found a close marker,
built fresh DOM beside its orphaned server copy, and reported a false
mismatch even with identical props. JSX <ErrorBoundary> (errorBlock) had the
same gap. @for and <Activity> stepped the cursor directly instead of through
parkPast, so an @if/@switch arm ending in any of these could not tell where
its content ended and kept the server's longer tail on screen unreported.

tryBlock (including its initial-suspense path), errorBlock, forBlock,
activityBlock, and childSlot now end with parkPast, as component and branch
slots already do. That makes #1578's close-marker step in discardArmTail and
rebuiltSlot's park-on-close redundant, so both are removed.

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

* fix(hydration): leave the cursor alone when a slot's parent was disposed

A boundary whose render disposed its parent (a cleanup error an ancestor
boundary caught) still parked past its own, now detached, range, which could
overwrite the cursor the ancestor's catch had placed. parkPast now skips a
disposed parent, matching componentSlotImpl and childSlot, which already
return before parking in that case. The check lives in HydrationCapability,
so non-hydrating bundles are unchanged.

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