Skip to content

fix(hydration): bound a suspended markerless branch arm by its own start comment - #1608

Merged
trueadm merged 1 commit into
mainfrom
claude/affectionate-cray-gsjabt
Oct 2, 2026
Merged

trueadm merged 1 commit into
mainfrom
claude/affectionate-cray-gsjabt

Conversation

@trueadm

@trueadm trueadm commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

When the server rendered no range for an @if/@switch, the client's arm takes the place of the server node at the hydration cursor (#1561's cursor mode). If that arm adopted the node in place, or had yet to clone, and then suspended inside a deferred <Hydrate split={false}> boundary, it kept only the static anchors. Those lie after later siblings' server content. #1561 listed this as open ("an adopted one needs a bounds design of its own"). On main, dev and prod:

  • Retry of the same arm: the boundary's same-branch finalize published the arm's range after the next sibling. That sibling then reported a false mismatch and built a second copy of its server node, for example <u>z</u><em>e</em><em>e</em>.
  • Case change while the activation is pending: the provisional sweep ran over the static bounds and removed the wrong nodes. With no arm ('b'), a duplicate <em> was built. With 'c', multi-root arms also duplicated.

This change:

  • Start comment: an arm that throws in cursor mode without a rebuilt root, and without fix(hydration): keep a rebuilt clone where the server node it replaced stood #1561's pending replacement, gets a client-owned start comment before its first node (holdMarkerlessBranch). No adoption claims or discards it, so it works for text cursors, multi-root arms and arms that suspended before clone(). It also records where the arm's content reached at the throw. It calls save() first, so a discarded speculative or root attempt rolls the comment back. Presentation attempts and adoption controls leave the DOM alone.
  • End of the held content: the later of that recorded point and where the arm's latest render left the cursor (heldBranchEnd). A later render can start from a cursor that an earlier sibling parked on the start comment, and slots the first attempt never reached adopt only in the retry.
  • Same-branch retry: finalizes from the start comment and removes it (dropHeldStart).
  • Case change: sweeps exactly the held content, then closes the start comment into a pair the slot owns (releaseHeldBranch). The marker path already builds an arm into a client-minted pair as client DOM, so the new arm adopts nothing and reports nothing.
  • markerlessEnd now takes the node before the arm and reads the end in whole nodes and server ranges. A cursor inside a range or a nested root ends the content after that unit, so a component frame is never split. A cursor that says nothing about the arm keeps only its first node or range: it never claims a later sibling's server nodes and never falls back to the static anchor. It keeps fix(hydration): keep a rebuilt clone where the server node it replaced stood #1561's result for an arm that adopted its host in place.

Nothing changes on the adoption happy path. The same-branch path has the same operation order as before, and all new work runs only for a markerless hydrating arm that threw.

Validation

  • pnpm format:check: ran the scoped pnpm format:files:check on the 4 changed files instead.
  • pnpm typecheck: ran pnpm typecheck:files on runtime.ts, the test and the .tsrx fixture instead; it is clean.
  • pnpm test: ran the octane and octane-prod projects instead; CI covers the rest.
  • targeted tests:
    • New tests/hydration/markerless-arm-retry.test.ts (dev and prod compile, 48 cases). Each of 7 arm shapes is run through the deferred retry and both case changes, 'b' and 'c'. The shapes are a single root adopted in place, the same under @if, an arm that suspends before clone(), server text, two roots, two roots after a leading sibling, and two roots suspending inside the second. They assert final DOM, that each server node is the same object, balanced client markers, and no recoverable errors or dev diagnostics. Each then switches case again. Three further cases cover a slot that first renders in the retry and two non-suspending arms (one ending inside its root, one running to the end of its parent arm), which pin markerlessEnd behavior that main already has.
    • On current main (3ec43da): 36 of 48 fail. All 14 retries and all 14 case 'b' changes fail, as do case 'c' for the 3 multi-root shapes and the later-slot retry. Before fix(hydration): stay quiet on a single-root mismatch under stale captures #1595/fix(hydration): build a deferred retry's update content on the client #1596, on 53db436, 44 failed.
    • Each part is load-bearing: I reverted each of 12 parts separately, and each made 2–44 cases fail. The parts are the start comment, the dropped start, the release into a pair, the held sweep end, the recorded progress, the post-render end, the retry's end, and five markerlessEnd rules (range interior, nested-root climb, later unit, stop-at-anchor, first-unit fallback).
    • Full octane + octane-prod on the pre-rebase head (on 53db436): 37,638 passed, 0 failed, 1,356 files.
    • Rebased head (on 3ec43da): tests/hydration and hmr.test.ts in both projects, 13,346 passed in 282 files. pnpm sync produced no changes.

Performance, rebased head against 3ec43da with the same commands unless noted:

  • Bundle size (benchmarks/bundle-size/run-minimal.mjs): hydrate-root +892 raw / +252 gzip, deferred-hydration +893 / +284. root-chained-jsx, cli-spa-starter and suspense-transition are byte-identical. The logic lives in HydrationCapability methods. An earlier draft called finalizeMarkerlessBranch from those methods, which pulled it into branch-free hydrating bundles, so finalization stays in renderBranchSlot.
  • Branch slot work (benchmarks/client-hot-paths/branches.mjs): against 53db436, hydration lookup counts, work guards and semantic outputs are identical. Wall-clock was measured on an earlier draft against fix(hydration): keep a rebuilt clone where the server node it replaced stood #1561's head, alternating base and candidate four times with 15 samples of 512 operations. The medians overlapped (ratios 0.97–1.05), so any difference is within noise.

Risk / follow-ups

  • Never-rendered slots in a replaced arm: if another case replaces a held arm before the slots its first attempt never reached have rendered, their server nodes can't be bounded. The next sibling then reports a mismatch.
  • Trailing static roots: a multi-root arm whose last root is static, or whose render runs off the end of a nested element, still ends after its first node or range. This applies to every cursor-mode arm, not just held ones.
  • Frame ambiguity (found while probing): a markerless @switch whose server content at the cursor starts with a component frame adopts that frame as its own range.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code

https://claude.ai/code/session_01G2K1tJXB6hzAV64suB7f7Q


Generated by Claude Code

…art comment

A @switch or @if that the server rendered no range for mounts its arm in
the place of the server node at the hydration cursor. When that arm
suspended inside a deferred <Hydrate split={false}> boundary without
rebuilding a root, it kept only the static anchors, which lie after later
siblings' server content. The boundary's retry then published the arm's
range after the next sibling, which reported a false mismatch and built a
second copy of its server node, and a case change while the boundary was
pending swept the wrong nodes.

The throwing arm now marks where its content starts with a client-owned
comment that no adoption claims or discards, and records where its content
reached. A retry finalizes the range from that comment, and a case change
removes exactly the arm's content and closes the comment into a pair the
next arm is built in as client DOM. markerlessEnd reads the end from whole
nodes and server ranges, so text, multi-root and nested-root arms are
bounded, and a cursor that says nothing about the arm never claims a later
sibling's server nodes.

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

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 21 value(s) increased
  • 🔴 bundle-reachability: 9 value(s) increased

Compares 3ec43daa4 with 3eabdbcde 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 3.80 3.84 +1.1% ±7% ⚪ within noise
octane-tsrx replace 8.85 9.19 +3.8% ±28% ⚪ within noise
octane-tsrx add 3.86 4.08 +5.7% ±28% ⚪ within noise
octane-tsrx update 0.50 0.63 +26.0% ±44% ⚪ within noise
octane-tsrx select 0.24 0.23 −4.2% ±55% ⚪ within noise
octane-tsrx swap 0.53 0.56 +5.7% ±44% ⚪ within noise
octane-tsrx remove 0.45 0.46 +2.2% ±65% ⚪ within noise
octane-tsrx runlots 37.70 39.14 +3.8% ±44% ⚪ within noise
octane-tsrx select_lots 0.35 0.29 −17.1% ±53% ⚪ within noise
octane-tsrx clear 49.34 42.74 −13.4% ±14% ⚪ within noise
octane-jsx run 4.43 3.92 −11.5% ±36% ⚪ within noise
octane-jsx replace 10.66 9.39 −11.9% ±47% ⚪ within noise
octane-jsx add 3.75 3.68 −1.9% ±28% ⚪ within noise
octane-jsx update 0.68 0.70 +2.9% ±45% ⚪ within noise
octane-jsx select 0.46 0.47 +2.2% ±35% ⚪ within noise
octane-jsx swap 0.81 0.91 +12.3% ±36% ⚪ within noise
octane-jsx remove 0.76 0.80 +5.3% ±54% ⚪ within noise
octane-jsx runlots 33.31 32.50 −2.4% ±16% ⚪ within noise
octane-jsx select_lots 3.35 2.63 −21.5% ±48% ⚪ within noise
octane-jsx clear 47.67 49.13 +3.1% ±24% ⚪ within noise

Application bundle size (bytes)

target metric base head Δ
octane-tsrx todo_js_raw 141,842 142,075 +233 (+0.2%) 🔴
octane-tsrx todo_js_gzip 46,829 46,933 +104 (+0.2%) 🔴
octane-tsrx todo_js_brotli 41,092 41,143 +51 (+0.1%) 🔴
octane-tsrx todo_app_gzip 2,476 2,477 +1 (+0.0%) 🔴
octane-tsrx todo_app_brotli 2,121 2,117 −4 (−0.2%) 🟢
octane-tsrx todo_fw_raw 136,732 136,965 +233 (+0.2%) 🔴
octane-tsrx todo_fw_gzip 44,353 44,456 +103 (+0.2%) 🔴
octane-tsrx todo_fw_brotli 38,971 39,026 +55 (+0.1%) 🔴
octane-tsrx chat_js_raw 141,051 141,284 +233 (+0.2%) 🔴
octane-tsrx chat_js_gzip 46,781 46,877 +96 (+0.2%) 🔴
octane-tsrx chat_js_brotli 41,136 41,210 +74 (+0.2%) 🔴
octane-tsrx chat_app_brotli 2,627 2,640 +13 (+0.5%) 🔴
octane-tsrx chat_fw_raw 134,398 134,631 +233 (+0.2%) 🔴
octane-tsrx chat_fw_gzip 43,802 43,898 +96 (+0.2%) 🔴
octane-tsrx chat_fw_brotli 38,509 38,570 +61 (+0.2%) 🔴
octane-tsrx weather_js_raw 178,001 178,234 +233 (+0.1%) 🔴
octane-tsrx weather_js_gzip 58,195 58,289 +94 (+0.2%) 🔴
octane-tsrx weather_js_brotli 50,613 50,822 +209 (+0.4%) 🔴
octane-tsrx weather_app_brotli 7,578 7,633 +55 (+0.7%) 🔴
octane-tsrx weather_fw_raw 151,266 151,499 +233 (+0.2%) 🔴
octane-tsrx weather_fw_gzip 49,150 49,244 +94 (+0.2%) 🔴
octane-tsrx weather_fw_brotli 43,035 43,189 +154 (+0.4%) 🔴

23 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
hydrate-root raw 167,251 168,143 +892 (+0.5%) 🔴
hydrate-root gzip 53,308 53,560 +252 (+0.5%) 🔴
hydrate-root brotli 46,419 46,703 +284 (+0.6%) 🔴
deferred-hydration raw 230,392 231,285 +893 (+0.4%) 🔴
deferred-hydration gzip 73,105 73,389 +284 (+0.4%) 🔴
deferred-hydration brotli 63,041 63,326 +285 (+0.5%) 🔴
binding-radix-esbuild gzip 68,614 68,622 +8 (+0.0%) 🔴
binding-radix-esbuild brotli 59,485 59,492 +7 (+0.0%) 🔴
binding-mantine-hooks-esbuild brotli 29,107 29,110 +3 (+0.0%) 🔴

96 other measured values are unchanged.

@trueadm
trueadm merged commit 6bb20ac into main Oct 2, 2026
54 checks passed
@trueadm
trueadm deleted the claude/affectionate-cray-gsjabt branch October 2, 2026 20:41
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