Repository navigation
fix(hydration): discard the server tail after an @if/@switch arm's last component - #1587
Merged
Merged
Conversation
…laim A hydrating @if/@switch arm whose content is its own component or branch slots left any server content after its last claimed range on the page, with nothing reported. Each claim now parks the cursor through HydrationCapability.parkPast, which records where it parked for the arm being adopted. renderAdoptedArm discards from there to the arm's end, stopping at nodes recovery rebuilt, and reports it once (new code 337 plus a dev diagnostic at the branch). It leaves the content when the arm cloned a template of its own, or a later slot registered after the last claim, because the cursor then rests on adopted roots rather than past them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fold the parked-claim rule into main's discardArmTail (#1564) instead of a second discard path: renderAdoptedArm now returns where the arm's last slot parked the cursor, and discardArmTail also discards from that node. The report follows #1564's convention (code 51, "the end of the branch"), so the new code 337 is dropped. The parks keep #1576's settleClaim and run after #1561's quiet sweepRebuiltTail. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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)
15 other measured values are unchanged. Public-import reachability bundles (bytes)
71 other measured values are unchanged. |
trueadm
marked this pull request as ready for review
October 2, 2026 18:29
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
A hydrating
@if/@switcharm whose client content is only its own component or branch slots left any server content after its last claimed range on the page, with nothing reported. A minimal repro, with every component framed:Server render with
server: true, then hydrate without it. On main the result is<s>s</s><b>a</b><u>tail</u>, with no recoverable error and no dev warning, in both dev and prod. #1564'sdiscardArmTailonly fires when the cursor rests on an open marker, and here it rests on<u>.The cursor after an arm body is not a reliable "consumed up to" marker on its own, because
clone()leaves it on an adopted root. This change adds a record of where a range claim made directly by the arm parked the cursor:HydrationCapability.parkPast(close, parent)replaces the plainnode = getNextSibling(end)advance at three sites:componentSlotLite(after fix(hydration): discard the server tail of an adopted component range #1576'ssettleClaim),componentSlotImpl, and the end ofrenderBranchSlot. Whenparentis the arm being adopted, it also records the parked node and the arm's slot count.renderAdoptedArm(block)wraps the arm's first hydratingrenderBlock. It saves and restores the outer arm's record intry/finally, so nested arms and throws are safe. It returns the parked node only when:adopt()seals the record whenCURRENT_SCOPE.blockis the arm), andslotsonly grows). That covers a later component adopting the parked node without a range, whatever path it adopts through.discardArmTailalso discards from that node, alongside its existing open-marker rule. It keeps fix(hydration): discard server ranges a shorter @if/@switch arm leaves unclaimed #1564's conventions: stop at nodes recovery rebuilt, code 51 plus one dev "the end of the branch" diagnostic, quiet understaleServerValues. fix(hydration): keep a rebuilt clone where the server node it replaced stood #1561's quietsweepRebuiltTailstill runs first.Validation
pnpm format:check: not run repo-wide;pnpm format:files:checkpasses on every changed file.pnpm typecheck: not run. Before the merge with main,pnpm typecheck:filespassed onruntime.ts, the test and the.tsrxfixture.pnpm test: not run.tests/hydration/branch-arm-claim-tail.test.ts, 28 cases × dev/prod compile, passed 56/56 across theoctaneandoctane-prodprojects.staleServerValues, the lite, full and branch park sites, and the fresh-node stop.Left unverified locally:
discardArmTail, and it switched the expected recoverable message from a draft code 337 to code 51.octane+octane-prodrun before the merge crashed early with a Vitest worker EPIPE under load, so it gave no result either way.Bundle (
benchmarks/bundle-size/run-minimal.mjs), measured before the merge:No wall-clock measurement was trustworthy at that load. The per-claim cost during hydration is one method call and one field compare.
Risk / follow-ups
fix/branch-arm-host-tails) has these tests, and planned to fold the same parked-claim rule into itsrenderArmor ship it right after. Whichever lands second should keep a single rule at this call site.@tryand Activity at an arm's top level don't record a park yet. A server tail after them stays as before (a safe miss).Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Touches core hydration control-flow in
runtime.ts(cursor parking and arm tail discard), but behavior is narrowly scoped to branch arms and is heavily regression-tested.Overview
Fixes a silent hydration bug where the server rendered a longer
@if/@switcharm than the client (e.g. extra trailing markup after the same framed components) and that leftover DOM stayed on the page with noonRecoverableErroror dev warning.The runtime now tracks where each arm’s last server range claim parks the hydration cursor via
parkPast(replacing baregetNextSiblingadvances after component and branch slots) andrenderAdoptedArmfor the arm’s first adopting render.discardArmTailis extended to remove unclaimed server nodes from that parked position as well as the existing open-marker case, while still preserving adopted nodes and reporting the mismatch once.Adds a broad hydration fixture and test suite (
branch-arm-claim-tail) covering@switch, nested branches, lazy/pending children,@try, and dormantHydrateboundaries.Reviewed by Cursor Bugbot for commit 4fcf359. Bugbot is set up for automated code reviews on this repo. Configure here.