Repository navigation
fix(hydration): bound a suspended markerless branch arm by its own start comment - #1608
Merged
Merged
Conversation
…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
trueadm
marked this pull request as ready for review
October 2, 2026 20:24
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)
23 other measured values are unchanged. Public-import reachability bundles (bytes)
96 other measured values are unchanged. |
This was referenced Oct 2, 2026
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
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"). Onmain, dev and prod:<u>z</u><em>e</em><em>e</em>.'b'), a duplicate<em>was built. With'c', multi-root arms also duplicated.This change:
holdMarkerlessBranch). No adoption claims or discards it, so it works for text cursors, multi-root arms and arms that suspended beforeclone(). It also records where the arm's content reached at the throw. It callssave()first, so a discarded speculative or root attempt rolls the comment back. Presentation attempts and adoption controls leave the DOM alone.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.dropHeldStart).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.markerlessEndnow 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 scopedpnpm format:files:checkon the 4 changed files instead.pnpm typecheck: ranpnpm typecheck:filesonruntime.ts, the test and the.tsrxfixture instead; it is clean.pnpm test: ran theoctaneandoctane-prodprojects instead; CI covers the rest.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 beforeclone(), 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 pinmarkerlessEndbehavior thatmainalready has.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.markerlessEndrules (range interior, nested-root climb, later unit, stop-at-anchor, first-unit fallback).octane+octane-prodon the pre-rebase head (on 53db436): 37,638 passed, 0 failed, 1,356 files.tests/hydrationandhmr.test.tsin both projects, 13,346 passed in 282 files.pnpm syncproduced no changes.Performance, rebased head against 3ec43da with the same commands unless noted:
benchmarks/bundle-size/run-minimal.mjs):hydrate-root+892 raw / +252 gzip,deferred-hydration+893 / +284.root-chained-jsx,cli-spa-starterandsuspense-transitionare byte-identical. The logic lives inHydrationCapabilitymethods. An earlier draft calledfinalizeMarkerlessBranchfrom those methods, which pulled it into branch-free hydrating bundles, so finalization stays inrenderBranchSlot.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
@switchwhose server content at the cursor starts with a component frame adopts that frame as its own range.Provenance
agent-authored)🤖 Generated with Claude Code
https://claude.ai/code/session_01G2K1tJXB6hzAV64suB7f7Q
Generated by Claude Code