Repository navigation
fix(hydration): discard and report a server arm under a client arm that renders nothing - #1580
Merged
Merged
Conversation
…erver rendered router-core's browser build of getScrollRestorationScriptForRouter always returns null, so the client hydrated ScrollRestorationScript's empty arm over the server's ScriptOnce arm and the server <script> stayed in the document with no report. The client now takes the arm the server took, ScriptOnce adopts the server script without comparing its content and drops it after hydration, and a client-only ScriptOnce renders nothing as upstream's does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…at renders nothing An @if with no client arm discards the server's other arm and reports it as an empty branch, but a client arm with an empty body (@else { <></> }) claimed nothing and left the server arm on screen with no report: #1564's tail discard skipped an arm whose cursor never left its first node. That cursor position is only ambiguous at elements and text, which a template adopts without moving the cursor; every range an arm claims moves it. When the arm's first node opens a server range, discard it and report an empty branch, as the null-body path does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
October 2, 2026 15:46
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 one arm of an
@if/@switchand the client's arm renders nothing (@else { <></> }), hydration left the server's arm in the DOM and reported nothing. An@ifwith no client arm at all (body === null) already discards that content and reports it as "an empty branch". This makes the two consistent.#1564's
discardArmTailskipped an arm that claimed nothing, because the cursor is still on the arm's first node and cannot tell adoption from no adoption. That ambiguity only exists for elements and text, which a template adopts without moving the cursor. Every range an arm claims moves the cursor past it. So when the cursor is still on the arm's first node and that node opens a server range, the arm rendered nothing there, and the whole range is the server's other arm. It is now discarded, with one structuralonRecoverableErrorand a development diagnostic at the directive: "the client expected an empty branch". A dormant<Hydrate>boundary whose captures changed still discards silently, as before. Element and text first nodes stay as they were.Stacked on #1579, which fixes the router binding that relied on this silence. Its scroll restoration script arm hid exactly this mismatch on every website route. Until that lands, this branch carries its commit, and the diff narrows once it merges.
Validation
pnpm format:check: not run repo-wide;pnpm format:files:checkon the changed files passespnpm typecheck: not run repo-wide;pnpm typecheck:fileson the changed files passespnpm sync: no generated changespnpm test: not run in full locallypackages/octane/tests/hydration/branch-arm-tail.test.ts, dev and production compile. fix(hydration): discard server ranges a shorter @if/@switch arm leaves unclaimed #1564's "does not report a client arm that renders nothing" case becomes: discards and reports once for an empty@elseand for an@ifwithout an else (the same report text). It also checks a matching empty arm adopts without a report, and a pending sibling's root replay reports once. 60/60 pass inoctane+octane-prod; onmain's runtime, 8 fail.octaneandoctane-prodVitest projects in full: 1337/1338 files and 37048/37049 tests pass. The one failure was a 5s timeout inhmr.test.ts(octane-prod) on a heavily loaded machine; that file passes alone (74/74 across both projects).website/tests/ssr-hydration.e2e.test.ts --maxWorkers=1: 69/69 pass (dev SSR and production preview, no hydration-mismatch warnings) with this change and fix(tanstack-router): hydrate the scroll restoration script arm the server rendered #1579.node benchmarks/bundle-size/run-minimal.mjs, baseline → candidate, bytes): hydrate-root raw 161538→161531, gzip 51736→51735, brotli 44991→45010; deferred-hydration raw 223967→223960, gzip 71234→71230, brotli 61465→61440; suspense-transition unchanged (166494 / 53485 / 46736). The change removes a comparison; the new message is development-only.Risk / follow-ups
@else { <></> }arms are the two in the router binding fixed by fix(tanstack-router): hydrate the scroll restoration script arm the server rendered #1579. An arm that renders nothing at runtime through a nested@ifor an earlyreturnalready took the null-body path.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Changes core SSR hydration control-flow handling and will surface recoverable errors where mismatches were previously silent; router scroll-restoration scripts now depend on adopt-then-remove during hydrate.
Overview
Hydration now treats a client
@if/@switcharm that renders nothing (for example@else { <></> }or no else) the same as a missing client arm:discardArmTailno longer bails out when the cursor is still on the branch start, so stale server content is removed and a single structuralonRecoverableErroris raised, with a dev message of "an empty branch" instead of silently leaving the server's other arm in the DOM. Element/text-first server arms are unchanged.@octanejs/tanstack-routeraligns with that behavior:ScrollRestorationScriptkeeps the server-side arm when router-core's browser build returns no script body, andScriptOnceadopts the server<script>during hydration (withsuppressHydrationWarning), drops it afteruseHydrated, and renders nothing on client-only mounts like upstream React Router.Coverage adds
branch-arm-tailcases and ascroll-restoration-hydrationconformance suite.Reviewed by Cursor Bugbot for commit 17a179f. Bugbot is set up for automated code reviews on this repo. Configure here.