Skip to content

fix(hydration): park past every boundary, list, and activity range - #1621

Merged
trueadm merged 5 commits into
mainfrom
fix/try-slot-cursor-park
Oct 3, 2026
Merged

trueadm merged 5 commits into
mainfrom
fix/try-slot-cursor-park

Conversation

@trueadm

@trueadm trueadm commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes review findings C1-1 (P1) and C1-4 (P2) from the 2026-10-02 sweep. Both come from one cause: some slots did not move the hydration cursor past their own server range.

  • C1-1: a @try never parked past its range. In a body with no template, such as <>@try {…}<Pair /></>, the next multi-root component found a close marker, built fresh DOM after its orphaned server copy, and reported a false mismatch even with identical props: <u>ok</u><i>u</i><s>s</s><i>u</i><s>s</s>. A client-thrown @try behaved the same way. JSX <ErrorBoundary> (errorBlock) had the identical gap, which the review did not list.
  • C1-4: @for and <Activity> moved the cursor directly instead of through parkPast, so the enclosing arm never recorded where they ended. An @if/@switch arm ending in a @for, @try (adopted, client-thrown or still loading), <ErrorBoundary> or <Activity> therefore kept the server's longer element or text tail on screen, with no report.

Changes

  • tryBlock, errorBlock, forBlock (both exits), activityBlock and childSlot now end with hydration?.parkPast(end, parentScope), as component and branch slots already did.
    • tryBlock's initial-suspense path now reaches the same park instead of returning early.
    • errorBlock's mount path moves into mountErrorBoundary, so the boundary has one exit and one park.
  • Removed two workarounds this makes redundant:
  • Hydration only. For a client-only render, each new call site is one null check.

Not included: the review patch's markerless and in-place hunks. Those are C1-2 (owned by another session), C1-3 and C1-5.

Validation

  • pnpm format:check (scoped pnpm format:files:check on the changed files: clean)
  • pnpm typecheck (scoped pnpm typecheck:files on the changed files: only the two existing tryboundary.tsrx errors, which main's versions show too)
  • pnpm test (not run locally; left to CI)
  • targeted tests:
    • New cases in try-hydrate.test.ts and branch-arm-tail.test.ts, 28 across the dev and prod compiles, all failing on main:
      • a @try or <ErrorBoundary> followed by a multi-root component, with matching props and with a client throw, keeping every server node and reporting nothing;
      • element and text tails after an arm ending in @for, @try, <ErrorBoundary>, <Activity> or a @try still loading on the client, discarded with one report;
      • matching arms of the same shapes, kept with no report.
    • Reverting each change on its own turns tests red: @try 12, <ErrorBoundary> 6, @for 4, <Activity> 2, initial-suspense path 2.
    • Related hydration suites under --project octane and --project octane-prod before the rebase onto fix(signals): load the browser's own query selection over a seed for another request #1618:
    • The reviewer's _review_C1_tail repro now fails only cases 8, 9 and 11a/11b, which are C1-3, C1-5 and C1-2.

Risk / follow-ups

  • No .tsrx shape I could construct observes the childSlot park. A {hole} always gives the arm a <!> template whose claimRoots end takes precedence. It is kept so every slot parks the same way, and only the existing suites cover it.
  • Size, measured with a one-off esbuild minify (benchmarks not run):
    • without hydration, @try adds about 22 B raw and 10 B gzip, @for about 6 B raw and 7 B gzip;
    • with hydration, the bundle shrinks by 8 B raw and 32 B gzip;
    • brotli moves by up to ±50 B, which is within its noise.

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 across many slot types; behavior is well-covered by new tests but incorrect parking could still cause subtle SSR/client DOM mismatches.

Overview
Fixes hydration cursor drift after @try, <ErrorBoundary>, @for, and <Activity> by parking past each slot’s server range the same way components and branches already do.

Sibling adoption: When a boundary left the cursor inside its own range, a following multi-root sibling (e.g. <>@try {…}<Pair /></>) could miss its server nodes, duplicate DOM, and raise false mismatches. tryBlock and errorBlock now always end with parkPast; errorBlock mount logic is consolidated so every path shares one exit.

Branch arm tails: @for, <Activity>, and childSlot switch from manual getNextSibling to parkPast, so @if/@switch arms that end in those slots can discard the server’s extra tail and report once via discardArmTail. rebuiltSlot always steps past the slot end; parkPast no-ops when the parent block was disposed; the old close-marker workaround in discardArmTail is removed.

New hydration fixtures and tests cover pair-after-boundary adoption, list/try/boundary/activity tails, client-thrown boundaries, and pending @try arms.

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

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]>
@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 23:42

@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: Park after disposed error boundary
    • Added a !state.parentBlock.disposed guard to the parkPast call in errorBlock so that when mountErrorBoundary returns early due to parent disposal, the caller no longer overwrites the hydration cursor an ancestor catch boundary already placed.

Create PR

Or push these changes by commenting:

@cursor push 8dca775895
Preview (8dca775895)
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
@@ -39105,8 +39105,11 @@ export function errorBlock(
 		}
 	} else mountErrorBoundary(state, hydration);
 	// Hydration: park past the boundary's range, as every slot does, so a
-	// following sibling adopts its own server content.
-	if (!state.passthrough) hydration?.parkPast(state.end, parentScope);
+	// following sibling adopts its own server content.  Skip when the parent was
+	// disposed during mount — an ancestor boundary already owns the cursor and
+	// state.end may be detached.
+	if (!state.passthrough && !state.parentBlock.disposed)
+		hydration?.parkPast(state.end, parentScope);
 	return state.reset;
 }
 

@@ -39105,8 +39105,11 @@ export function errorBlock(
 		}
 	} else mountErrorBoundary(state, hydration);
 	// Hydration: park past the boundary's range, as every slot does, so a
-	// following sibling adopts its own server content.
-	if (!state.passthrough) hydration?.parkPast(state.end, parentScope);
+	// following sibling adopts its own server content.  Skip when the parent was
+	// disposed during mount — an ancestor boundary already owns the cursor and
+	// state.end may be detached.
+	if (!state.passthrough && !state.parentBlock.disposed)
+		hydration?.parkPast(state.end, parentScope);
 	return state.reset;
 }

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

Reviewed by Cursor Bugbot for commit c3462a9. Configure here.

Comment thread packages/octane/src/runtime.ts Resolved
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]>
@trueadm
trueadm marked this pull request as ready for review October 2, 2026 23:50
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 22 value(s) increased
  • 🔴 bundle-reachability: 20 value(s) increased

Compares 8e900489e with 30fd1cb3c 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.05 3.72 −8.1% ±30% ⚪ within noise
octane-tsrx replace 9.31 9.02 −3.1% ±22% ⚪ within noise
octane-tsrx add 3.89 3.63 −6.7% ±22% ⚪ within noise
octane-tsrx update 0.60 0.56 −6.7% ±38% ⚪ within noise
octane-tsrx select 0.23 0.24 +4.3% ±63% ⚪ within noise
octane-tsrx swap 0.43 0.43 −0.0% ±37% ⚪ within noise
octane-tsrx remove 0.40 0.50 +25.0% ±59% ⚪ within noise
octane-tsrx runlots 34.97 34.06 −2.6% ±18% ⚪ within noise
octane-tsrx select_lots 0.29 0.25 −13.8% ±45% ⚪ within noise
octane-tsrx clear 48.57 48.95 +0.8% ±8% ⚪ within noise
octane-jsx run 3.98 3.84 −3.5% ±8% ⚪ within noise
octane-jsx replace 9.80 9.24 −5.7% ±22% ⚪ within noise
octane-jsx add 3.65 3.47 −4.9% ±24% ⚪ within noise
octane-jsx update 0.70 0.70 +0.0% ±33% ⚪ within noise
octane-jsx select 0.49 0.44 −10.2% ±32% ⚪ within noise
octane-jsx swap 0.94 0.78 −17.0% ±47% ⚪ within noise
octane-jsx remove 0.83 0.70 −15.7% ±25% ⚪ within noise
octane-jsx runlots 32.07 32.10 +0.1% ±10% ⚪ within noise
octane-jsx select_lots 3.15 2.57 −18.4% ±22% ⚪ within noise
octane-jsx clear 51.19 50.25 −1.8% ±13% ⚪ within noise

Application bundle size (bytes)

target metric base head Δ
octane-tsrx js_raw 126,864 126,850 −14 (−0.0%) 🟢
octane-tsrx js_gzip 41,971 41,978 +7 (+0.0%) 🔴
octane-tsrx js_brotli 36,974 37,005 +31 (+0.1%) 🔴
octane-tsrx app_gzip 2,564 2,563 −1 (−0.0%) 🟢
octane-tsrx app_brotli 2,227 2,226 −1 (−0.0%) 🟢
octane-tsrx fw_raw 119,352 119,338 −14 (−0.0%) 🟢
octane-tsrx fw_gzip 39,407 39,415 +8 (+0.0%) 🔴
octane-tsrx fw_brotli 34,747 34,779 +32 (+0.1%) 🔴
octane-tsrx todo_js_raw 142,251 142,237 −14 (−0.0%) 🟢
octane-tsrx todo_js_gzip 46,988 46,993 +5 (+0.0%) 🔴
octane-tsrx todo_js_brotli 41,257 41,173 −84 (−0.2%) 🟢
octane-tsrx todo_app_gzip 2,477 2,478 +1 (+0.0%) 🔴
octane-tsrx todo_app_brotli 2,117 2,121 +4 (+0.2%) 🔴
octane-tsrx todo_fw_raw 137,141 137,127 −14 (−0.0%) 🟢
octane-tsrx todo_fw_gzip 44,511 44,515 +4 (+0.0%) 🔴
octane-tsrx todo_fw_brotli 39,140 39,052 −88 (−0.2%) 🟢
octane-tsrx chat_js_raw 141,460 141,446 −14 (−0.0%) 🟢
octane-tsrx chat_js_gzip 46,933 46,937 +4 (+0.0%) 🔴
octane-tsrx chat_js_brotli 41,254 41,277 +23 (+0.1%) 🔴
octane-tsrx chat_app_gzip 2,979 2,978 −1 (−0.0%) 🟢
octane-tsrx chat_app_brotli 2,637 2,639 +2 (+0.1%) 🔴
octane-tsrx chat_fw_raw 134,807 134,793 −14 (−0.0%) 🟢
octane-tsrx chat_fw_gzip 43,954 43,959 +5 (+0.0%) 🔴
octane-tsrx chat_fw_brotli 38,617 38,638 +21 (+0.1%) 🔴
octane-tsrx weather_js_raw 178,413 178,412 −1 (−0.0%) 🟢
octane-tsrx weather_js_gzip 58,335 58,345 +10 (+0.0%) 🔴
octane-tsrx weather_js_brotli 50,770 50,794 +24 (+0.0%) 🔴
octane-tsrx weather_app_gzip 9,045 9,044 −1 (−0.0%) 🟢
octane-tsrx weather_fw_raw 151,678 151,677 −1 (−0.0%) 🟢
octane-tsrx weather_fw_gzip 49,290 49,301 +11 (+0.0%) 🔴
octane-tsrx weather_fw_brotli 43,190 43,214 +24 (+0.1%) 🔴
octane-jsx js_raw 226,723 226,725 +2 (+0.0%) 🔴
octane-jsx js_gzip 72,360 72,362 +2 (+0.0%) 🔴
octane-jsx js_brotli 62,690 62,642 −48 (−0.1%) 🟢
octane-jsx app_gzip 2,937 2,936 −1 (−0.0%) 🟢
octane-jsx app_brotli 2,500 2,510 +10 (+0.4%) 🔴
octane-jsx fw_raw 218,264 218,266 +2 (+0.0%) 🔴
octane-jsx fw_gzip 69,423 69,426 +3 (+0.0%) 🔴
octane-jsx fw_brotli 60,190 60,132 −58 (−0.1%) 🟢

6 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
cli-spa-starter raw 116,556 116,542 −14 (−0.0%) 🟢
cli-spa-starter gzip 39,347 39,358 +11 (+0.0%) 🔴
cli-spa-starter brotli 34,393 34,372 −21 (−0.1%) 🟢
root-static raw 203,051 203,053 +2 (+0.0%) 🔴
root-static gzip 64,554 64,558 +4 (+0.0%) 🔴
root-static brotli 55,950 55,909 −41 (−0.1%) 🟢
hydrate-root raw 171,079 171,031 −48 (−0.0%) 🟢
hydrate-root gzip 54,316 54,295 −21 (−0.0%) 🟢
hydrate-root brotli 47,392 47,400 +8 (+0.0%) 🔴
deferred-hydration raw 234,493 234,470 −23 (−0.0%) 🟢
deferred-hydration gzip 74,202 74,192 −10 (−0.0%) 🟢
deferred-hydration brotli 64,035 64,010 −25 (−0.0%) 🟢
suspense-transition raw 167,390 167,401 +11 (+0.0%) 🔴
suspense-transition gzip 53,803 53,810 +7 (+0.0%) 🔴
suspense-transition brotli 47,025 46,962 −63 (−0.1%) 🟢
binding-base-ui-vite raw 213,242 213,244 +2 (+0.0%) 🔴
binding-base-ui-vite gzip 68,122 68,126 +4 (+0.0%) 🔴
binding-base-ui-vite brotli 59,025 59,074 +49 (+0.1%) 🔴
binding-base-ui-esbuild raw 211,199 211,201 +2 (+0.0%) 🔴
binding-base-ui-esbuild gzip 68,106 68,109 +3 (+0.0%) 🔴
binding-base-ui-esbuild brotli 59,103 59,025 −78 (−0.1%) 🟢
binding-radix-vite raw 215,172 215,174 +2 (+0.0%) 🔴
binding-radix-vite gzip 68,695 68,698 +3 (+0.0%) 🔴
binding-radix-vite brotli 59,532 59,547 +15 (+0.0%) 🔴
binding-radix-esbuild raw 213,089 213,091 +2 (+0.0%) 🔴
binding-radix-esbuild gzip 68,694 68,697 +3 (+0.0%) 🔴
binding-radix-esbuild brotli 59,588 59,585 −3 (−0.0%) 🟢
binding-apollo-client-vite raw 358,297 358,299 +2 (+0.0%) 🔴
binding-apollo-client-vite gzip 112,249 112,252 +3 (+0.0%) 🔴
binding-apollo-client-vite brotli 98,041 97,943 −98 (−0.1%) 🟢
binding-apollo-client-esbuild raw 361,246 361,248 +2 (+0.0%) 🔴
binding-apollo-client-esbuild gzip 114,460 114,463 +3 (+0.0%) 🔴
binding-apollo-client-esbuild brotli 99,645 99,622 −23 (−0.0%) 🟢

72 other measured values are unchanged.

@trueadm

trueadm commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator Author

Benchmark report reviewed; no change needed. The size deltas are the expected cost of moving @for's cursor step onto parkPast and adding one parkPast call to @try and <ErrorBoundary>:

  • Raw bytes go down 14 B (−48 B in hydrate-root).
  • Gzip goes up 3–12 B per app.
  • Brotli moves by up to about ±70 B, both ways.

hydrate-root shrinks on all three measures because #1578's close-marker step is gone. The benchmark report check passed, and the timing rows are all within noise.

🤖 Addressed by Claude Code

@trueadm
trueadm merged commit 3315f74 into main Oct 3, 2026
30 checks passed
@trueadm
trueadm deleted the fix/try-slot-cursor-park branch October 3, 2026 00:55
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