Repository navigation
fix(hydration): discard an arm's tail after a @try that rebuilt its arm - #1578
Merged
Merged
Conversation
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]>
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: Single close step misses nested tails
- Changed the single
if (this.isClose(from))towhile (this.isClose(from) && from !== end)so that consecutive close markers from nested rebuilt slots are all skipped before the open-tail check.
- Changed the single
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.
Contributor
Benchmark report
Compares js-framework: 1k/10k row operations (ms, lower is better)All 20 timed operations (20 within noise)
Application bundle size (bytes)
27 other measured values are unchanged. Public-import reachability bundles (bytes)
72 other measured values are unchanged. |
trueadm
marked this pull request as ready for review
October 2, 2026 15:52
…rker # Conflicts: # packages/octane/src/runtime.ts
This was referenced Oct 2, 2026
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]>
5 of 7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
Follow-up to #1564, fixing the Cursor Bugbot finding left open when #1564 merged (review thread).
discardArmTailremoves the server content that a shorter client@if/@switcharm leaves unclaimed. It looks for that content at the hydration cursor. Nested slots normally park the cursor past their range. A@trywhose body throws on the client during hydration is the exception: it builds its catch arm fresh andrebuiltSlotparks the cursor on the boundary's close marker. When that boundary ends the client arm,discardArmTailsaw 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.The server renders
{ on: false }withBoomrendering fine. The client hydrates{ on: true }withBoomthrowing. 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 structuralonRecoverableErrorplus 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
discardArmTailnow 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:
@for(with and without items), nested@if(true and false), a nested@trythat adopts or suspends, and a throwing@trywrapped 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.cursor/close-marker-cursor-logic-eaafwith a loop over consecutive close markers and anIfTryThenTailtest. That test passes onmainwithout 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
pnpm format:check: I ranpnpm format:files:checkon the changed files instead (passes).pnpm typecheck: I ranpnpm typecheck:fileson the changed files, with the.tsrxfixture passed explicitly (passes).pnpm test: I ran theoctaneandoctane-prodVitest projects instead (results below).CaughtLastcase intests/hydration/branch-arm-tail.test.ts(dev and prod compiles): the final DOM, the adopted<em>identity, exactly one recoverable error, and the exact development diagnostic. It fails without the change.tests/hydration/on this base, which includes fix(hydration): rebuild component calls in an adopted element with other server content #1563: 12,176 passed in both projects.octane+octane-prodand the website SSR hydration spec on the equivalent change before fix(hydration): rebuild component calls in an adopted element with other server content #1563 landed: 36,926 passed with 3 load timeouts inhydration-ssr-diagnosticsandvolar(both pass alone), and the website spec passed 69/69.octane+octane-prodon 379a2b9: 37,017 passed across 1,338 files, with no failures.main(fix(hydration): continue after a component adopted in place without a range #1567, perf(octane): keep the fresh-hydration closure out of componentSlotImpl #1571, fix(compiler): leave hook methods called during module init unslotted #1572) at ab93655:tests/hydration/passed 12,202/12,202. The full projects passed 37,057, with 2behavior-rootload timeouts; that file passes 414/414 alone. The website SSR spec passed 68/69 with no hydration mismatches; the 69th is the flaky playground keyword-hover test, which passes alone in dev and prod.@tryor child slot leaving consecutive close markers): it doesn't reproduce. A throwing@tryinside another@try, inside a component's child slot, and inside a value hole each discard the tail with exactly one report, because the enclosing slot parks the cursor past its own range. The single step stays (details in the thread).pnpm syncleaves the tree clean.Risk / follow-ups
renderBranchSlotis unchanged.goofy-bhaskarasession), and the TanStack Router scroll-restoration arm swap (separate follow-up).Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith 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/@switcharms ending in throwing@tryboundaries.Overview
Fixes a hydration gap when a shorter client
@if/@switcharm ends with a@trywhose body throws during hydration: the boundary rebuilds the catch arm and leaves the cursor on its close marker, sodiscardArmTailused to bail out and leave extra server-only nodes (e.g. a trailing<em>z</em>) with no recoverable error.discardArmTailnow advances one sibling past a close marker before scanning for unclaimed server content, then discards and reports a single structuralonRecoverableErroras before. Comments document the close-marker case.Adds
CaughtLastfixture and a hydration test that asserts the corrected DOM, one recoverable error, and the dev diagnostic. Patch changeset foroctane.Reviewed by Cursor Bugbot for commit 515f2ff. Bugbot is set up for automated code reviews on this repo. Configure here.