Skip to content

fix(hydration): keep a later sibling's server range when a component without one is built - #1589

Merged
trueadm merged 6 commits into
mainfrom
claude/mystifying-feynman-987ab8-oqeans
Oct 2, 2026
Merged

trueadm merged 6 commits into
mainfrom
claude/mystifying-feynman-987ab8-oqeans

Conversation

@trueadm

@trueadm trueadm commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

When hydration finds no server range for a component call (for example a component that rendered nothing on the server in the arm being hydrated), componentSlotImpl builds it fresh and HydrationCapability.renderUnframed discards the server nodes left in its place. That discard loop only stopped at the anchor, the fresh start marker, or a block close. It ran straight through a later sibling call's <!--[--> open marker and content, so:

  • the sibling's server range was destroyed and it rebuilt without a mismatch report of its own;
  • a stray <!--]--> close marker was left in the DOM;
  • the fresh component's markers were appended at the end of the parent range, behind the siblings it should precede.

This change:

  • adds HydrationCapability.unframedReplaces(node, anchor): a server node is discarded only if it is ahead of the anchor and is neither a block open, a block close, nor a client-built (fresh) node. A block open belongs to a later sibling, which claims it.
  • adds unframedBefore(stale, anchor), used by both componentSlotImpl and mountUnframedLite, to mint the fresh comp markers in place of the replaced server nodes, so the component stays ahead of later siblings.

Validation

  • pnpm format:check (scoped pnpm format:files:check on the changed files instead)
  • pnpm typecheck (scoped pnpm typecheck:files on runtime.ts, the test and the fixture instead)
  • pnpm test (the octane and octane-prod Vitest projects instead; CI runs the rest)
  • targeted tests: new packages/octane/tests/hydration/unframed-component-siblings.test.ts, with dev and prod compiles of four shapes (empty component first, empty then a ranged sibling, a pair then a ranged sibling, host-wrapped empty first) plus toggle-off/on updates afterwards. It fails on main and passes here.
  • Mutation checks, each red: the old sweep loop; dropping the componentSlotImpl placement; dropping the mountUnframedLite placement; dropping the fresh-node stop (red in fix(hydration): rebuild component calls in an adopted element with other server content #1563's adopted-host-component-clone sibling cases).
  • pnpm staged-dom:check, pnpm sync (no changes).
  • After merging current main: all 258 hydration test files pass in octane + octane-prod (12504 tests).
  • octane + octane-prod Vitest projects, at the previous merge of main: 37090 passed, 4 failed. The 4 failures are behavior-root.test.ts > preserves destructured props through getter reentry, abort and recovery (dev/prod × both projects). They fail the same way on main without this change.
  • node benchmarks/bundle-size/run-minimal.mjs on this head and on main at the previous merge, with budget gates passing: +37 raw / +11–18 gzip in the scenarios that pull in the component slot, hydrate-root +116 / +32, deferred-hydration +153 / +51. All other scenarios are unchanged.

Risk / follow-ups

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code

https://claude.ai/code/session_01Te3NJRzy6R5Vkkc7KuJvys


Generated by 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
Changes hydration DOM surgery and sibling range adoption when server/client component shapes diverge; mistakes could leave stray markers or wrong subtree adoption, though the path is narrow and heavily tested.

Overview
Fixes hydration when a component call has no server range and is rebuilt on the client: discard and marker placement no longer swallow a later sibling’s adopted server range.

HydrationCapability gains unframedReplaces so renderUnframed removes only placeholder server nodes (not block open/close markers or fresh client nodes), and unframedBefore so componentSlotImpl and mountUnframedLite insert fresh comp markers in place of those nodes instead of appending at the parent end. Siblings can still adopt their ranges, DOM order stays correct, and hydration markers stay balanced.

Adds a changeset plus unframed-component-siblings fixture/tests (dev and prod compile) covering empty/multi-root/lite-first shapes and post-hydration toggles.

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

trueadm and others added 6 commits October 2, 2026 16:17
…without one is built

A component call that finds no server range of its own renders between fresh
markers, then hydration discards the server nodes in its place. The discard ran
until a block close, so it consumed a later sibling call's range open marker and
content and stopped at that range's close, which stayed behind as a stray marker.
The sibling then rebuilt its server content without a report of its own.

The discard now stops at any block marker or client-built node, leaving a later
range for the sibling call that claims it. The fresh markers go where the
discarded nodes stood (HydrationCapability.unframedBefore) rather than at the
parent range's end, so the built component stays ahead of siblings that adopt
their server ranges. componentSlot and the anchorless lite path both use it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nman-987ab8-oqeans

# Conflicts:
#	packages/octane/src/runtime.ts
#1561 added a public HydrationCapability.replaces(node) for rebuilt roots.
The merge kept both methods, so the later definition overrode the unframed
sweep's private replaces(node, anchor). Name the sweep's predicate
unframedReplaces.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Te3NJRzy6R5Vkkc7KuJvys
@trueadm
trueadm marked this pull request as ready for review October 2, 2026 18:19
@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 commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Benchmark report

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

Compares 18fbcb06b with c9e0db1f7 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.38 3.85 −12.1% ±35% ⚪ within noise
octane-tsrx replace 9.81 10.58 +7.8% ±61% ⚪ within noise
octane-tsrx add 4.65 4.35 −6.5% ±45% ⚪ within noise
octane-tsrx update 0.64 0.60 −6.2% ±43% ⚪ within noise
octane-tsrx select 0.26 0.33 +26.9% ±66% ⚪ within noise
octane-tsrx swap 0.50 0.59 +18.0% ±78% ⚪ within noise
octane-tsrx remove 0.39 0.51 +30.8% ±57% ⚪ within noise
octane-tsrx runlots 36.61 32.80 −10.4% ±33% ⚪ within noise
octane-tsrx select_lots 0.27 0.30 +11.1% ±48% ⚪ within noise
octane-tsrx clear 50.47 47.23 −6.4% ±17% ⚪ within noise
octane-jsx run 4.00 3.95 −1.2% ±23% ⚪ within noise
octane-jsx replace 7.93 8.85 +11.6% ±31% ⚪ within noise
octane-jsx add 3.69 3.60 −2.4% ±30% ⚪ within noise
octane-jsx update 0.69 0.79 +14.5% ±36% ⚪ within noise
octane-jsx select 0.52 0.52 −0.0% ±45% ⚪ within noise
octane-jsx swap 0.75 0.82 +9.3% ±38% ⚪ within noise
octane-jsx remove 0.68 0.72 +5.9% ±41% ⚪ within noise
octane-jsx runlots 32.27 31.92 −1.1% ±28% ⚪ within noise
octane-jsx select_lots 3.29 2.62 −20.4% ±52% ⚪ within noise
octane-jsx clear 54.43 49.80 −8.5% ±30% ⚪ within noise

Application bundle size (bytes)

target metric base head Δ
octane-tsrx weather_js_raw 177,447 177,484 +37 (+0.0%) 🔴
octane-tsrx weather_js_gzip 58,013 58,026 +13 (+0.0%) 🔴
octane-tsrx weather_js_brotli 50,370 50,478 +108 (+0.2%) 🔴
octane-tsrx weather_app_brotli 7,582 7,632 +50 (+0.7%) 🔴
octane-tsrx weather_fw_raw 150,712 150,749 +37 (+0.0%) 🔴
octane-tsrx weather_fw_gzip 48,968 48,981 +13 (+0.0%) 🔴
octane-tsrx weather_fw_brotli 42,788 42,846 +58 (+0.1%) 🔴
octane-jsx js_raw 225,636 225,673 +37 (+0.0%) 🔴
octane-jsx js_gzip 72,064 72,077 +13 (+0.0%) 🔴
octane-jsx js_brotli 62,396 62,320 −76 (−0.1%) 🟢
octane-jsx fw_raw 217,169 217,206 +37 (+0.0%) 🔴
octane-jsx fw_gzip 69,121 69,134 +13 (+0.0%) 🔴
octane-jsx fw_brotli 59,895 59,819 −76 (−0.1%) 🟢

32 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
root-static raw 201,955 201,992 +37 (+0.0%) 🔴
root-static gzip 64,211 64,229 +18 (+0.0%) 🔴
root-static brotli 55,630 55,659 +29 (+0.1%) 🔴
context raw 110,283 110,320 +37 (+0.0%) 🔴
context gzip 36,508 36,523 +15 (+0.0%) 🔴
context brotli 32,306 32,331 +25 (+0.1%) 🔴
hydrate-root raw 164,499 164,639 +140 (+0.1%) 🔴
hydrate-root gzip 52,553 52,591 +38 (+0.1%) 🔴
hydrate-root brotli 45,699 45,814 +115 (+0.3%) 🔴
deferred-hydration raw 227,262 227,439 +177 (+0.1%) 🔴
deferred-hydration gzip 72,179 72,241 +62 (+0.1%) 🔴
deferred-hydration brotli 62,238 62,350 +112 (+0.2%) 🔴
suspense-transition raw 166,795 166,832 +37 (+0.0%) 🔴
suspense-transition gzip 53,606 53,629 +23 (+0.0%) 🔴
suspense-transition brotli 46,785 46,814 +29 (+0.1%) 🔴
binding-base-ui-vite raw 212,145 212,182 +37 (+0.0%) 🔴
binding-base-ui-vite gzip 67,819 67,835 +16 (+0.0%) 🔴
binding-base-ui-vite brotli 58,685 58,724 +39 (+0.1%) 🔴
binding-base-ui-esbuild raw 210,114 210,151 +37 (+0.0%) 🔴
binding-base-ui-esbuild gzip 67,748 67,767 +19 (+0.0%) 🔴
binding-base-ui-esbuild brotli 58,764 58,814 +50 (+0.1%) 🔴
binding-radix-vite raw 214,075 214,112 +37 (+0.0%) 🔴
binding-radix-vite gzip 68,343 68,353 +10 (+0.0%) 🔴
binding-radix-vite brotli 59,287 59,282 −5 (−0.0%) 🟢
binding-radix-esbuild raw 212,003 212,040 +37 (+0.0%) 🔴
binding-radix-esbuild gzip 68,353 68,369 +16 (+0.0%) 🔴
binding-radix-esbuild brotli 59,217 59,299 +82 (+0.1%) 🔴
binding-apollo-client-vite raw 357,197 357,234 +37 (+0.0%) 🔴
binding-apollo-client-vite gzip 111,906 111,925 +19 (+0.0%) 🔴
binding-apollo-client-vite brotli 97,599 97,598 −1 (−0.0%) 🟢
binding-apollo-client-esbuild raw 360,153 360,190 +37 (+0.0%) 🔴
binding-apollo-client-esbuild gzip 114,110 114,122 +12 (+0.0%) 🔴
binding-apollo-client-esbuild brotli 99,359 99,353 −6 (−0.0%) 🟢

72 other measured values are unchanged.

@trueadm
trueadm merged commit 56de31a into main Oct 2, 2026
50 of 53 checks passed
@trueadm
trueadm deleted the claude/mystifying-feynman-987ab8-oqeans branch October 2, 2026 18:36
trueadm added a commit that referenced this pull request Oct 2, 2026
…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]>
trueadm added a commit that referenced this pull request Oct 2, 2026
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]>
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