Skip to content

fix(hydration): keep later sibling ranges when a component range is missing - #1584

Merged
trueadm merged 4 commits into
mainfrom
claude/determined-babbage-x7us4t
Oct 2, 2026
Merged

trueadm merged 4 commits into
mainfrom
claude/determined-babbage-x7us4t

Conversation

@trueadm

@trueadm trueadm commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

When hydration finds other server content where a client component call expects its range (for example, the server rendered another @if/@switch arm), the component is now built where that content stood and only that content is discarded. Later sibling components keep their server ranges and adopt their server nodes, instead of being rebuilt with a second mismatch report.

  • HydrationCapability.renderUnframed used to insert the rebuilt component's markers at the slot's anchor (the end of the enclosing arm) and sweep server nodes until a close marker. That sweep ran through the next sibling's <!--[--> and content, so the sibling hydrated against the end of its parent and was rebuilt. The markers now go in place of the server node (unframedBefore), and the sweep stops at the next marker comment (discardInPlace): a later sibling's range or boundary, or the end of the enclosing range.
  • A component that suspends while built this way no longer reports and discards on the suspended attempt. It keeps its claim (unframedClaims), so the server content stays on screen. The attempt that completes reports once and discards, both on a preserved <Hydrate> resume (renderSuspended renders the suspended leaf without adopting; the slot's re-render completes the claim) and on a root retry.
  • rebuildFragment defers its report and discard to drainFrag (placeRebuilt). A fragment rebuilt over another component's range whose use() hole suspends now leaves the server content on screen and reports once.
  • A hookless component rendered through the lite slot (development compile) that finds no range and rebuilds its fragment now discards only the server content in its place and is inserted there, instead of sweeping to the end marker it shares with later siblings. Its development diagnostic names the call site.

Validation

  • pnpm format:check: not run repo-wide. pnpm format:files:check on the changed files passes.
  • pnpm typecheck: not run repo-wide. pnpm typecheck:files on runtime.ts, the test, and the .tsrx fixture passes.
  • pnpm test: not run. The octane and octane-prod Vitest projects were run on the merged head (below).
  • targeted tests: new packages/octane/tests/hydration/unframed-component-range.test.ts (20 cases across development and production compiles) asserts final DOM, adopted-sibling identity, server content visible while suspended, and exact diagnostics. 17 fail on main's runtime; the 3 that pass are controls. The related hydration suites (32 files, including main's new in-place-component-sibling, adopted-component-tail and rebuilt-clone-* suites) pass in both projects: 1104 tests.
  • Full octane: 20,407 passed, 12 failed. Full octane-prod: 16,980 passed, 14 failed. Every failure is in behavior-root.test.ts, compiler/volar.test.ts or hydration-ssr-diagnostics.test.ts. Run alone, behavior-root fails the same 2 "getter reentry" tests on main's runtime and on this branch (likely the local Node 22.22.0, below the required 22.22.2); the others were load timeouts that pass alone.
  • Each part of the fix was broken deliberately (10 variations) and each break failed at least one regression.
  • pnpm staged-dom:check passes. The CI minimal bundle budget gate passes: 4 scenarios are byte-identical to main and context grows by 189 raw / 76 gzip / 48 brotli bytes.

Risk / follow-ups

  • When the client's arm is shorter than the server's and no later client sibling claims the leftover server range, there are two diagnostics: the replaced node, then the arm's tail.
  • While a child of a component built this way is suspended under <Hydrate>, the component's already-rendered client nodes show beside the server content (a preserved activation keeps partial client DOM).
  • Not fixed here, and reproducible on main: when a child component inside a fragment rebuilt over another component's range suspends under <Hydrate>, the server content is lost while pending and the resume throws NotFoundError.
  • If a slot's component identity changes before its suspended claim completes, the server node it replaced would stay. Untested.

Provenance

  • An agent produced this diff (agent-authored)

https://claude.ai/code/session_01LqA51dmsggKyu7uH3zc9N2


&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=1793555893&installation_model_id=432790&pr_number=1584&ref=codesmith_pr_footer&repository=octanejs%2Foctane&return_to=https%3A%2F%2Fgithub.com%2Foctanejs%2Foctane%2Fpull%2F1584&signature=1407ffd472b8270e5aff70362e4c75edc1fe3eae60dd3820d8850697eaa3d98a"&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
Touches core hydration cursor, discard, and suspense resume paths in runtime.ts; incorrect bounds could mis-adopt siblings or double-report mismatches, though coverage is broad.

Overview
Fixes hydration when the server left other content where a client component call expected its range (e.g. a different @if arm). The client now inserts fresh range markers in place of that server node and removes only nodes up to the next block marker (discardInPlace), so later siblings still adopt their server ranges instead of being swept and rebuilt with duplicate mismatch reports.

Suspense: unframed renders that throw suspense keep the claim (unframedClaims) and leave server DOM visible until a completing attempt; <Hydrate> resume uses renderSuspended so the leaf retries without adopting early. Fragment recovery defers mismatch reporting/discarding from rebuildFragment to placeRebuilt in drainFrag, including hookless lite-slot fragments over another component’s range.

Adds a patch changeset and unframed-component-range hydration tests (dev + prod compile).

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

claude added 2 commits October 2, 2026 17:44
…issing

When the server rendered other content where a client component call expects
its range, renderUnframed swept server nodes until a close marker. The sweep
ran through the next sibling component's open marker and content, so that
sibling hydrated against the end of its parent and was rebuilt with a second
diagnostic. It also ran on suspension, so a component that suspended blanked
the server content while pending.

The component's fresh markers now go where the server node they replace
stood, and the sweep stops at the next marker comment, leaving later
siblings' ranges and boundaries for them to adopt. A suspended render keeps
its claim instead of reporting and discarding: the attempt that completes
reports once and discards then, both on a preserved <Hydrate> resume and on
a root retry.

rebuildFragment now defers its report and discard to drainFrag, so a use()
hole that suspends leaves the server content on screen. Hookless fragment
components anchored at their parent's end take the same missing-range path
as other components, so dev and prod recover and report alike.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LqA51dmsggKyu7uH3zc9N2
Resolve runtime.ts against #1561, #1567 and #1576: keep main's adopted-range
claims (renderClaimed) and in-place lite rendering (renderInPlace) beside the
unframed-claim changes.

#1567 renders a lite call that found no range against the cursor, so a
hookless component that renders nothing leaves the server element to the next
call. Drop this branch's routing of such calls through the missing-range
path, which contradicted that. Fix the over-sweep where it happens instead:
when such a call rebuilds its fragment, placeRebuilt now discards only the
server content in its place, up to the next marker, and drainFrag inserts the
fragment there, ahead of later siblings' ranges. The development diagnostic
names the call site. renderUnframed shares the same bounded sweep
(discardInPlace).

The fixture's FragChild gets a hook so it is a full component call in both
compiles, which is the path that case covers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LqA51dmsggKyu7uH3zc9N2
@trueadm trueadm changed the title Fix unframed component hydration with later sibling ranges fix(hydration): keep later sibling ranges when a component range is missing 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 19:02
Resolve runtime.ts against #1589, which also stopped renderUnframed's sweep
at a later sibling's range and placed the fresh markers where the replaced
server node stood. Keep this branch's discardInPlace, whose sweep stops at
every marker and so covers #1589's block open/close stop, and its
unframedBefore. Drop #1589's unframedReplaces and its copy of unframedBefore,
which nothing calls after the merge.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm marked this pull request as ready for review October 2, 2026 19:08
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 19 value(s) increased
  • 🔴 bundle-reachability: 30 value(s) increased

Compares 5ef4f9a49 with 2969ff736 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.21 3.86 −8.3% ±39% ⚪ within noise
octane-tsrx replace 10.14 8.68 −14.4% ±57% ⚪ within noise
octane-tsrx add 3.67 3.61 −1.6% ±18% ⚪ within noise
octane-tsrx update 0.52 0.69 +32.7% ±61% ⚪ within noise
octane-tsrx select 0.20 0.23 +15.0% ±67% ⚪ within noise
octane-tsrx swap 0.58 0.41 −29.3% ±66% ⚪ within noise
octane-tsrx remove 0.52 0.40 −23.1% ±68% ⚪ within noise
octane-tsrx runlots 34.29 32.76 −4.5% ±34% ⚪ within noise
octane-tsrx select_lots 0.28 0.23 −17.9% ±80% ⚪ within noise
octane-tsrx clear 46.59 44.88 −3.7% ±24% ⚪ within noise
octane-jsx run 4.10 3.84 −6.3% ±23% ⚪ within noise
octane-jsx replace 9.20 8.22 −10.7% ±31% ⚪ within noise
octane-jsx add 3.59 3.29 −8.4% ±19% ⚪ within noise
octane-jsx update 0.73 0.63 −13.7% ±52% ⚪ within noise
octane-jsx select 0.48 0.48 +0.0% ±64% ⚪ within noise
octane-jsx swap 0.73 0.92 +26.0% ±61% ⚪ within noise
octane-jsx remove 0.61 0.73 +19.7% ±83% ⚪ within noise
octane-jsx runlots 32.16 32.70 +1.7% ±22% ⚪ within noise
octane-jsx select_lots 2.93 2.47 −15.7% ±48% ⚪ within noise
octane-jsx clear 47.79 48.26 +1.0% ±32% ⚪ within noise

Application bundle size (bytes)

target metric base head Δ
octane-tsrx todo_js_raw 141,739 141,775 +36 (+0.0%) 🔴
octane-tsrx todo_js_gzip 46,792 46,810 +18 (+0.0%) 🔴
octane-tsrx todo_js_brotli 40,969 41,025 +56 (+0.1%) 🔴
octane-tsrx todo_app_brotli 2,117 2,122 +5 (+0.2%) 🔴
octane-tsrx todo_fw_raw 136,629 136,665 +36 (+0.0%) 🔴
octane-tsrx todo_fw_gzip 44,315 44,333 +18 (+0.0%) 🔴
octane-tsrx todo_fw_brotli 38,852 38,903 +51 (+0.1%) 🔴
octane-tsrx weather_js_raw 177,593 177,780 +187 (+0.1%) 🔴
octane-tsrx weather_js_gzip 58,066 58,135 +69 (+0.1%) 🔴
octane-tsrx weather_js_brotli 50,546 50,597 +51 (+0.1%) 🔴
octane-tsrx weather_app_brotli 7,590 7,580 −10 (−0.1%) 🟢
octane-tsrx weather_fw_raw 150,858 151,045 +187 (+0.1%) 🔴
octane-tsrx weather_fw_gzip 49,022 49,091 +69 (+0.1%) 🔴
octane-tsrx weather_fw_brotli 42,956 43,017 +61 (+0.1%) 🔴
octane-jsx js_raw 226,031 226,183 +152 (+0.1%) 🔴
octane-jsx js_gzip 72,141 72,184 +43 (+0.1%) 🔴
octane-jsx js_brotli 62,398 62,480 +82 (+0.1%) 🔴
octane-jsx app_gzip 2,944 2,943 −1 (−0.0%) 🟢
octane-jsx fw_raw 217,564 217,716 +152 (+0.1%) 🔴
octane-jsx fw_gzip 69,197 69,241 +44 (+0.1%) 🔴
octane-jsx fw_brotli 59,896 59,978 +82 (+0.1%) 🔴

24 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
root-static raw 202,351 202,503 +152 (+0.1%) 🔴
root-static gzip 64,323 64,378 +55 (+0.1%) 🔴
root-static brotli 55,751 55,811 +60 (+0.1%) 🔴
context raw 110,385 110,537 +152 (+0.1%) 🔴
context gzip 36,548 36,605 +57 (+0.2%) 🔴
context brotli 32,347 32,409 +62 (+0.2%) 🔴
hydrate-root raw 165,971 166,934 +963 (+0.6%) 🔴
hydrate-root gzip 52,973 53,223 +250 (+0.5%) 🔴
hydrate-root brotli 46,086 46,339 +253 (+0.5%) 🔴
deferred-hydration raw 228,777 229,907 +1,130 (+0.5%) 🔴
deferred-hydration gzip 72,592 72,957 +365 (+0.5%) 🔴
deferred-hydration brotli 62,644 62,948 +304 (+0.5%) 🔴
suspense-transition raw 166,916 167,067 +151 (+0.1%) 🔴
suspense-transition gzip 53,658 53,699 +41 (+0.1%) 🔴
suspense-transition brotli 46,871 46,901 +30 (+0.1%) 🔴
binding-base-ui-vite raw 212,541 212,693 +152 (+0.1%) 🔴
binding-base-ui-vite gzip 67,904 67,953 +49 (+0.1%) 🔴
binding-base-ui-vite brotli 58,859 58,879 +20 (+0.0%) 🔴
binding-base-ui-esbuild raw 210,506 210,656 +150 (+0.1%) 🔴
binding-base-ui-esbuild gzip 67,896 67,941 +45 (+0.1%) 🔴
binding-base-ui-esbuild brotli 58,891 58,862 −29 (−0.0%) 🟢
binding-radix-vite raw 214,470 214,622 +152 (+0.1%) 🔴
binding-radix-vite gzip 68,444 68,495 +51 (+0.1%) 🔴
binding-radix-vite brotli 59,365 59,439 +74 (+0.1%) 🔴
binding-radix-esbuild raw 212,394 212,544 +150 (+0.1%) 🔴
binding-radix-esbuild gzip 68,496 68,545 +49 (+0.1%) 🔴
binding-radix-esbuild brotli 59,446 59,391 −55 (−0.1%) 🟢
binding-apollo-client-vite raw 357,594 357,746 +152 (+0.0%) 🔴
binding-apollo-client-vite gzip 112,014 112,074 +60 (+0.1%) 🔴
binding-apollo-client-vite brotli 97,791 97,749 −42 (−0.0%) 🟢
binding-apollo-client-esbuild raw 360,546 360,696 +150 (+0.0%) 🔴
binding-apollo-client-esbuild gzip 114,237 114,282 +45 (+0.0%) 🔴
binding-apollo-client-esbuild brotli 99,510 99,546 +36 (+0.0%) 🔴

72 other measured values are unchanged.

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