Skip to content

fix(hydration): report a mismatched range once across sibling components - #1585

Merged
trueadm merged 7 commits into
mainfrom
claude/youthful-cannon-op6rqr
Oct 2, 2026
Merged

trueadm merged 7 commits into
mainfrom
claude/youthful-cannon-op6rqr

Conversation

@trueadm

@trueadm trueadm commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Some hydration mismatches logged one dev diagnostic per component instead of one per recovery. This happens when a server range holds content the client doesn't render, and the client renders several sibling component calls in that range.

Example: the server renders text "server" in a {hole}, and the client's value for that hole is a component that renders two <Tally /> calls.

  • The first call reports the text, discards it up to the range's closing marker, and builds between fresh markers.
  • Every later sibling then found that closing marker and reported again: "the server rendered the end of the parent block".

Once a recovery reaches the range's closing marker, this change records that marker in the existing HYDRATION_REBUILT set, and only the first claim there reports (firstAtRangeEnd). In packages/octane/src/runtime.ts, these places report through firstAtRangeEnd:

  • renderUnframed: component slots from componentSlotImpl, plus anchorless lite calls.
  • adopt(): a fragment template that finds the cursor on a range end.
  • adopt(): a single-root template that finds the cursor on a range end. This combines with main's retry check (cursor !== this.replaced).

These record the marker without reporting again, through reachedRangeEnd:

  • rebuildFragment, when its discard reaches the range end.
  • adopt()'s single-root rebuild, when stepping past the replaced server node lands on the range end. This was Cursor Bugbot's finding.

A mismatch in a separate range still reports. onRecoverableError already fired once per hydration burst, so the duplicate only ever appeared in the dev console. The adoption fast path is unchanged; only mismatch-recovery branches moved.

New coverage: tests/hydration/component-range-siblings.test.ts with fixture _fixtures/component-range-siblings.tsrx, run under both the dev and prod compile. Cases:

  • Reported scenario: a single diagnostic, the server's button.after adopted, every component responds to clicks, and the hole swaps back and forth.
  • Variants:
    • An empty server range.
    • A hole in the root component's own output.
    • A control-flow arm.
    • A fragment clone, single-root clone or @if following the first component.
    • A component following a rebuilt fragment clone, or a rebuilt single-root clone.
  • Controls: two separate mismatched holes still produce two diagnostics, and a matching server render is adopted silently.

Changed expectations: the GateForm/RootForm never-suspends controls in suspended-clone-mismatch.test.ts and root-suspended-clone-mismatch.test.ts are the single-root case. There, <s> is rebuilt over <b>, then <i> lands on the range end. Their pinned dev count goes from 2 to 1, and the suspended attempts still match the controls.

Validation

  • pnpm format:check: not run repo-wide. pnpm format:files:check is clean on the changed files.
  • pnpm typecheck: not run repo-wide. pnpm typecheck:files packages/octane/src/runtime.ts is clean.
  • pnpm test: not run. I ran vitest --project octane --project octane-prod on the first commit: 37,068 passed and 4 failed. The 4 failures are 2 tests in behavior-root.test.ts ("getter reentry, abort and recovery"), run in both projects. They fail the same way on the base commit fdf54fe in this container, which runs Node 22.22.0 while the repo asks for ≥22.22.2.
  • targeted tests:
    • On the current head, which includes main at 0b0e10f, packages/octane/tests/hydration plus auto-memo-value-position.test.ts pass in both projects: 260 files, 12,530 tests.
    • Against main's runtime.ts, the new suite fails 10 of 22 tests (all dev-compile diagnostic assertions); with this change all 22 pass.
    • Removing any one of the edited sites turns at least one case red.
    • An over-broad "report once per hydration" rule fails the two-holes control.
  • pnpm sync produced no changes.

Bundle bytes (node benchmarks/bundle-size/run-minimal.mjs, and CI's benchmark report):

  • Client-only fixtures are byte-identical.
  • hydrate-root and deferred-hydration each grow by about +247 raw and +62 to +83 gzip bytes.
  • hydrate-root was already over its committed budget on the base commit, and CI doesn't gate that fixture.

Risk / follow-ups

  • A later hydration attempt that finds a recorded range end also stays quiet. This matches what the HYDRATION_REBUILT set is documented to do. A root attempt that rolls back, or a discarded speculative attempt, forgets the entry through the existing journal/undo.
  • The behavior-root failures above predate this change and are untouched here.

Provenance

  • An agent produced this diff (agent-authored)

https://claude.ai/code/session_01CkBkcRuEtVuENx2eTJF9Gv


&lt;source media="(prefers-color-scheme: dark)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/view-with-codesmith-dark-v2.svg"&gt;&lt;source media="(prefers-color-scheme: light)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/view-with-codesmith-light-v2.svg"&gt;&lt;img alt="View with [code]smith" src="https://pr-comments-assets.blacksmith.sh/codesmith/view-with-codesmith-dark-v2.svg"&gt; <a href="https://backend.blacksmith.sh/track/enable-autofix?expires=1793556081&installation_model_id=432790&pr_number=1585&ref=codesmith_pr_footer&repository=octanejs%2Foctane&return_to=https%3A%2F%2Fgithub.com%2Foctanejs%2Foctane%2Fpull%2F1585&signature=ba23989284b80252b638600cbca4753a0ad612d0fb061891f77848eeacd6dc1e"&gt;&lt;picture&gt;&lt;source media="(prefers-color-scheme: dark)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark.svg"&gt;&lt;source media="(prefers-color-scheme: light)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-light.svg"&gt;&lt;img alt="Autofix with [code]smith" src="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark.svg"&gt;
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Medium Risk
Changes hydration mismatch-recovery reporting in runtime.ts; DOM adoption paths are intended to stay the same, but incorrect deduplication could hide real mismatches or over-suppress warnings.

Overview
Hydration mismatch recovery no longer emits a separate dev-console diagnostic for every sibling component when one server range is rebuilt. If the server left text (or other content) where the client renders multiple component calls, the first sibling still reports and discards up to the range end; later siblings that land on that same closing marker no longer repeat "the end of the parent block".

The runtime tracks range ends already handled in the existing HYDRATION_REBUILT set via firstAtRangeEnd and reachedRangeEnd, wired through renderUnframed, fragment/single-root adopt(), and rebuildFragment. Separate mismatched ranges still get their own warnings; matching server markup is unchanged.

Adds component-range-siblings fixture/tests (dev and prod compile) and lowers expected structural warning counts in the suspended clone mismatch controls from 2 to 1 where a second sibling previously duplicated the report.

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

When a server range holds content the client does not render, such as
server text in a hole whose client value is a component that renders two
component calls, the first call reports the server node, discards it up
to the end of the range, and builds between fresh markers. Every later
sibling then found the cursor on that range end and reported again ("the
server rendered the end of the parent block"), so one recovery logged a
dev diagnostic per sibling.

Remember the range end in HYDRATION_REBUILT once a recovery reaches it.
renderUnframed (component slots), the fragment and single-root template
claims that find the cursor on a range end, and rebuildFragment now share
firstAtRangeEnd, so only the first claim at that end reports. A mismatch
in a separate range still reports on its own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01CkBkcRuEtVuENx2eTJF9Gv

@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-root discard skips range-end mark
    • After discardCursor in the single-root mismatch path, the adoption cursor can land on the enclosing range-end marker without recording it in HYDRATION_REBUILT; adding the same remember call used by rebuildFragment prevents later siblings from emitting a duplicate diagnostic.

Create PR

Or push these changes by commenting:

@cursor push 54ed0819ac
Preview (54ed0819ac)
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
@@ -19966,6 +19966,8 @@
 				return this.freshClone(template);
 			}
 			this.discardCursor(cursor);
+			if (this.node != null && isBlockClose(this.node))
+				this.remember((HYDRATION_REBUILT ??= new WeakSet()), this.node);
 			if (claimsRoot)
 				this.claimRootRemainder(
 					framedRemainder === undefined ? (unframedRemainder ?? null) : framedRemainder,

diff --git a/packages/octane/tests/hydration/_fixtures/component-range-siblings.tsrx b/packages/octane/tests/hydration/_fixtures/component-range-siblings.tsrx
--- a/packages/octane/tests/hydration/_fixtures/component-range-siblings.tsrx
+++ b/packages/octane/tests/hydration/_fixtures/component-range-siblings.tsrx
@@ -62,6 +62,13 @@
 	</>
 }
 
+function SingleThenTally() @{
+	<>
+		<Single />
+		<Tally name="inner2" />
+	</>
+}
+
 function TallyThenIf() @{
 	<>
 		<Tally name="inner" />
@@ -77,6 +84,7 @@
 	PlainThenTally,
 	TallyThenSingle,
 	TallyThenIf,
+	SingleThenTally,
 };
 
 // A component named by `value`, or else `value` itself as text.

diff --git a/packages/octane/tests/hydration/component-range-siblings.test.ts b/packages/octane/tests/hydration/component-range-siblings.test.ts
--- a/packages/octane/tests/hydration/component-range-siblings.test.ts
+++ b/packages/octane/tests/hydration/component-range-siblings.test.ts
@@ -211,6 +211,14 @@
 			actual: 'text "server"',
 		},
 		{
+			when: 'a hookless single-root precedes a component',
+			name: 'Content',
+			server: { value: 'server' },
+			client: { value: 'SingleThenTally' },
+			expected: '<i>',
+			actual: 'text "server"',
+		},
+		{
 			when: 'an @if arm follows the first component',
 			name: 'Content',
 			server: { value: 'server' },

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

Reviewed by Cursor Bugbot for commit eeae6f8. Configure here.

Comment thread packages/octane/src/runtime.ts Resolved
…n-op6rqr

# Conflicts:
#	packages/octane/src/runtime.ts
@trueadm trueadm changed the title Report hydration mismatch once per sibling component range fix(hydration): report a mismatched range once across sibling components Oct 2, 2026
@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 18:13
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-reachability: 6 value(s) increased

Compares 53db43656 with 75ea1d71d 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)

target operation base head Δ noise
octane-jsx select 0.63 0.40 −36.5% ±27% 🟢 faster
All 20 timed operations (19 within noise)
target operation base head Δ noise
octane-tsrx run 3.75 3.74 −0.3% ±14% ⚪ within noise
octane-tsrx replace 8.76 8.91 +1.7% ±33% ⚪ within noise
octane-tsrx add 3.62 3.50 −3.3% ±11% ⚪ within noise
octane-tsrx update 0.64 0.37 −42.2% ±58% ⚪ within noise
octane-tsrx select 0.30 0.21 −30.0% ±52% ⚪ within noise
octane-tsrx swap 0.47 0.48 +2.1% ±61% ⚪ within noise
octane-tsrx remove 0.44 0.48 +9.1% ±87% ⚪ within noise
octane-tsrx runlots 36.53 33.44 −8.5% ±28% ⚪ within noise
octane-tsrx select_lots 0.29 0.31 +6.9% ±60% ⚪ within noise
octane-tsrx clear 57.39 45.25 −21.2% ±43% ⚪ within noise
octane-jsx run 4.93 3.92 −20.5% ±44% ⚪ within noise
octane-jsx replace 10.66 8.96 −15.9% ±39% ⚪ within noise
octane-jsx add 4.20 3.57 −15.0% ±18% ⚪ within noise
octane-jsx update 0.90 0.67 −25.6% ±32% ⚪ within noise
octane-jsx select 0.63 0.40 −36.5% ±27% 🟢 faster
octane-jsx swap 1.04 0.76 −26.9% ±41% ⚪ within noise
octane-jsx remove 0.88 0.76 −13.6% ±35% ⚪ within noise
octane-jsx runlots 35.28 30.96 −12.2% ±20% ⚪ within noise
octane-jsx select_lots 3.21 2.52 −21.5% ±48% ⚪ within noise
octane-jsx clear 47.22 46.46 −1.6% ±21% ⚪ within noise

Application bundle size (bytes)

No changes across 45 measured values.

Public-import reachability bundles (bytes)

target metric base head Δ
hydrate-root raw 165,126 165,430 +304 (+0.2%) 🔴
hydrate-root gzip 52,726 52,800 +74 (+0.1%) 🔴
hydrate-root brotli 45,882 45,943 +61 (+0.1%) 🔴
deferred-hydration raw 227,932 228,236 +304 (+0.1%) 🔴
deferred-hydration gzip 72,362 72,440 +78 (+0.1%) 🔴
deferred-hydration brotli 62,452 62,535 +83 (+0.1%) 🔴
binding-aria-esbuild gzip 3,363 3,361 −2 (−0.1%) 🟢
binding-aria-esbuild brotli 3,013 3,012 −1 (−0.0%) 🟢
binding-radix-esbuild gzip 68,374 68,373 −1 (−0.0%) 🟢
binding-radix-esbuild brotli 59,318 59,272 −46 (−0.1%) 🟢

95 other measured values are unchanged.

claude added 2 commits October 2, 2026 18:32
A single-root clone that mismatches a server node rebuilds over it and
steps the cursor past it. When that step lands on the end of the server
range, a later sibling there still reported a second "the server
rendered the end of the parent block" diagnostic for the same recovery
(Cursor Bugbot). Record that end as rebuilt, as rebuildFragment does,
through a shared reachedRangeEnd.

The GateForm/RootForm controls in the suspended-clone suites are this
case (<s> rebuilt over <b>, then <i> at the range end), so they now
publish one diagnostic; the suspended attempts still match them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01CkBkcRuEtVuENx2eTJF9Gv
@trueadm
trueadm marked this pull request as ready for review October 2, 2026 18:46
trueadm and others added 3 commits October 2, 2026 19:51
…n-op6rqr

Resolve renderUnframed against #1589, which mints the fresh markers in
place of the stale server nodes and stops the discard at a later sibling's
range. The discard can no longer reach the fresh markers, so the range-end
check reads the node it stopped on directly.

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

Resolve adopt's single-root mismatch path against #1593: keep the PR's
atRangeEnd check and reachedRangeEnd mark alongside #1593's lite-host
parent guard and lite endMarker step.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm merged commit 70ee6a3 into main Oct 2, 2026
4 of 23 checks passed
@trueadm
trueadm deleted the claude/youthful-cannon-op6rqr branch October 2, 2026 19:14
trueadm added a commit that referenced this pull request Oct 2, 2026
Resolve runtime.ts against #1585 and #1599.

#1585 reports a mismatched range once across sibling components: the
discard runs before the report, which is skipped when the discard stopped
at a range end an earlier recovery already reported (firstAtRangeEnd).
renderUnframed keeps that order with this branch's discardInPlace, which
returns where it stopped. placeRebuilt's in-place discard also records a
range end it reaches (reachedRangeEnd), as its other discard does.

#1599 names the static root after a fragment's leading holes in the
rebuilt-fragment warning. That warning now lives in placeRebuilt, so it
takes the template from the rebuilt record and keeps the lite call's site.

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.

2 participants