Repository navigation
fix(hydration): stay quiet on a single-root mismatch under stale captures - #1595
Merged
Merged
Conversation
…ures When a Hydrate boundary's captures change before it activates, the server HTML predates the client's state and recovery is meant to be silent. The single-root mismatch path in HydrationCapability.adopt reported 51 (and a dev structural warning) regardless. A @switch case swapped while the boundary was pending after adopting the server's case, or a changed case rendered over the server's case on early activation, therefore called onRecoverableError although the DOM was repaired correctly. Fragment, text, list and empty arms were already quiet. Route the report through reportStructural(), which every other structural report site already uses. Unchanged captures still report. 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)No changes across 45 measured values. Public-import reachability bundles (bytes)
100 other measured values are unchanged. |
trueadm
marked this pull request as ready for review
October 2, 2026 19:14
…/suspicious-poincare-a72333 # Conflicts: # packages/octane/src/runtime.ts
This was referenced Oct 2, 2026
Merged
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 a
<Hydrate>boundary's captures change before it activates, the server HTML predates the client's state, and recovery is documented to be silent (docs/deferred-hydration.md). The single-root mismatch path inHydrationCapability.adoptignoredstaleServerValues. It calledonRecoverableErrorand, in dev, logged "the client expected<b>but the server rendered …" even though the DOM was repaired correctly.Two ways to hit it:
@switchcase changes while a deferred boundary is still pending, after the old case already adopted the server's range. The swap removes the old case, and the new one renders with the cursor on the slot's close marker.Fragment, text, list and empty arms were already quiet. Elements, components and a nested
@ifreported.The fix routes the report through
reportStructural(), which every other structural report site already uses. Unchanged captures still report.Why not build the incoming arm with hydration suspended in
renderBranchSlot? The DOM was already correct for every arm shape probed. The cursor sits on the slot's own close marker, so the arm cannot take server nodes. That fix would also miss the early-activation case, which has no swap. And it would silence branch flips during a hydration pass that stale captures don't explain; those still report.Validation
pnpm format:check(not run repo-wide;pnpm format:files:checkon all changed files passes)pnpm typecheck(not run repo-wide;pnpm typecheck:filesonruntime.ts, the test, and the.tsrxfixture exits 0)pnpm testequivalent:vitest run --project octane --project octane-prod, 1,351 files / 37,390 tests passed (before merging the latestmain)hydration/stale-capture-branch.test.tswith dev and prod compiles, in both projects. Without the fix, 8 tests fail: both stale scenarios × 2 compiles × 2 projects. With it, all 16 pass. After mergingmain, that file plusbranch-arm-claim-tail,branch-arm-tail,unframed-component-siblings,independent-island,initial-document-signalsandrebuilt-clone-suspendedpass in both projects (280 tests).The regressions assert:
<section>and<em>are the same nodes;onRecoverableErrorand no dev warning;A control asserts that a case the server did not render is still reported when captures are unchanged.
Bundle size (
benchmarks/bundle-size/run-minimal.mjs, production), baseline → candidate:hydrate-rootdeferred-hydrationroot-static(client only)The changed branch runs only on a template-root mismatch, so render paths are unaffected.
CI's bench report flags compressed growth of +1 to +110 bytes on
hydrate-rootanddeferred-hydration, with raw size flat (−1). That is compression-window movement from replacing the inlinenoteRecoverableHydrationError(...)call withthis.reportStructural(). Locally, an inline!this.staleServerValuesgate was no smaller: +25 raw on both, with brotli +43 and +25, against +6 and +36 forreportStructural().Risk / follow-ups
<C />swap or a keyed-list insert renders a new block from a cursor that points at another block's adopted server node, and takes it. A swapped component loses the suspended sibling; inserting a row drops an existing one. This predates fix(hydration): keep a rebuilt clone where the server node it replaced stood #1561. This PR removes the false report on that path, not the corruption.staleServerValues(~runtime.ts:34672). Not changed here because I haven't confirmed it's reachable.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 mismatch reporting in
runtime.ts; behavior change is scoped to stale-capture recovery, with regression tests, but false negatives/positives around branch swaps are possible.Overview
When a
<Hydrate>boundary’s captures change before activation, a@switch/@ifarm that no longer matches server HTML is rebuilt on the client without noise. The single-root structural mismatch path in hydrationadoptnow goes throughreportStructural()(like other structural reports), soonRecoverableErrorand dev “client expected … but server rendered …” warnings are skipped whenstaleServerValuesapplies. Real mismatches with unchanged captures still report.Adds a changeset, a fixture (
Ranged/Dormant), and hydration tests (dev + prod compile) for pending-boundary case swaps, early activation, and the unchanged-capture control.Reviewed by Cursor Bugbot for commit cf1372b. Bugbot is set up for automated code reviews on this repo. Configure here.