Skip to content

fix(hydration): stay quiet on a single-root mismatch under stale captures - #1595

Merged
trueadm merged 3 commits into
mainfrom
claude/suspicious-poincare-a72333
Oct 2, 2026
Merged

trueadm merged 3 commits into
mainfrom
claude/suspicious-poincare-a72333

Conversation

@trueadm

@trueadm trueadm commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

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 in HydrationCapability.adopt ignored staleServerValues. It called onRecoverableError and, in dev, logged "the client expected <b> but the server rendered …" even though the DOM was repaired correctly.

Two ways to hit it:

  • A @switch case 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.
  • A changed case renders over the server's case when a capture change activates a dormant boundary early. No swap is involved.

Fragment, text, list and empty arms were already quiet. Elements, components and a nested @if reported.

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:check on all changed files passes)
  • pnpm typecheck (not run repo-wide; pnpm typecheck:files on runtime.ts, the test, and the .tsrx fixture exits 0)
  • pnpm test equivalent: vitest run --project octane --project octane-prod, 1,351 files / 37,390 tests passed (before merging the latest main)
  • targeted tests: hydration/stale-capture-branch.test.ts with 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 merging main, that file plus branch-arm-claim-tail, branch-arm-tail, unframed-component-siblings, independent-island, initial-document-signals and rebuilt-clone-suspended pass in both projects (280 tests).

The regressions assert:

  • the final DOM;
  • that the server <section> and <em> are the same nodes;
  • no onRecoverableError and no dev warning;
  • that the slot keeps working afterwards.

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:

Scenario Raw Gzip Brotli
hydrate-root 0 +1 +84
deferred-hydration −1 +3 +46
root-static (client only) 0 0 0

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-root and deferred-hydration, with raw size flat (−1). That is compression-window movement from replacing the inline noteRecoverableHydrationError(...) call with this.reportStructural(). Locally, an inline !this.staleServerValues gate was no smaller: +25 raw on both, with brotli +43 and +25, against +6 and +36 for reportStructural().

Risk / follow-ups

  • Separate DOM defect, tracked in its own session. In the same stale deferred retry, a dynamic <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.
  • A child that flips its parent's branch during the hydration render still reports through the swap path. React would apply that update after the hydration commit and report no mismatch. Left unchanged here.
  • The deopt dynamic-tag mismatch path also skips staleServerValues (~runtime.ts:34672). Not changed here because I haven't confirmed it's reachable.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with 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/@if arm that no longer matches server HTML is rebuilt on the client without noise. The single-root structural mismatch path in hydration adopt now goes through reportStructural() (like other structural reports), so onRecoverableError and dev “client expected … but server rendered …” warnings are skipped when staleServerValues applies. 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.

trueadm and others added 2 commits October 2, 2026 19:56
…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]>
@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
@github-actions
github-actions Bot marked this pull request as draft October 2, 2026 18:59
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-reachability: 3 value(s) increased

Compares 70ee6a381 with 8d2510f72 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 4.67 5.86 +25.5% ±95% ⚪ within noise
octane-tsrx replace 8.45 9.96 +17.9% ±50% ⚪ within noise
octane-tsrx add 4.12 5.95 +44.4% ±67% ⚪ within noise
octane-tsrx update 0.51 0.55 +7.8% ±62% ⚪ within noise
octane-tsrx select 0.18 0.18 ±0.0% ±62% ⚪ within noise
octane-tsrx swap 0.51 0.57 +11.8% ±53% ⚪ within noise
octane-tsrx remove 0.44 0.50 +13.6% ±61% ⚪ within noise
octane-tsrx runlots 40.34 51.77 +28.3% ±60% ⚪ within noise
octane-tsrx select_lots 0.21 0.23 +9.5% ±55% ⚪ within noise
octane-tsrx clear 37.22 44.10 +18.5% ±38% ⚪ within noise
octane-jsx run 4.31 4.81 +11.6% ±27% ⚪ within noise
octane-jsx replace 8.50 9.74 +14.6% ±29% ⚪ within noise
octane-jsx add 4.65 4.43 −4.7% ±70% ⚪ within noise
octane-jsx update 0.86 1.01 +17.4% ±75% ⚪ within noise
octane-jsx select 0.41 0.70 +70.7% ±61% ⚪ within noise
octane-jsx swap 0.69 1.06 +53.6% ±63% ⚪ within noise
octane-jsx remove 0.79 0.69 −12.7% ±98% ⚪ within noise
octane-jsx runlots 43.52 40.70 −6.5% ±84% ⚪ within noise
octane-jsx select_lots 3.20 2.97 −7.2% ±57% ⚪ within noise
octane-jsx clear 36.97 37.41 +1.2% ±22% ⚪ within noise

Application bundle size (bytes)

No changes across 45 measured values.

Public-import reachability bundles (bytes)

target metric base head Δ
hydrate-root gzip 52,825 52,822 −3 (−0.0%) 🟢
hydrate-root brotli 45,991 45,997 +6 (+0.0%) 🔴
deferred-hydration raw 228,305 228,304 −1 (−0.0%) 🟢
deferred-hydration gzip 72,449 72,455 +6 (+0.0%) 🔴
deferred-hydration brotli 62,531 62,567 +36 (+0.1%) 🔴

100 other measured values are unchanged.

@trueadm
trueadm marked this pull request as ready for review October 2, 2026 19:14
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.

1 participant