Skip to content

fix(hydration): report a suspended root's rebuilt mismatch once - #1551

Merged
trueadm merged 4 commits into
mainfrom
fix/root-suspended-hydration-mismatch
Oct 2, 2026
Merged

trueadm merged 4 commits into
mainfrom
fix/root-suspended-hydration-mismatch

Conversation

@trueadm

@trueadm trueadm commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A root with no Suspense boundary now reports a hydration mismatch once when it suspends during hydration. Previously, if the root's first attempt had rebuilt a mismatched clone before suspending, that attempt published its diagnostics even though the attempt was discarded. The retry then reported the same mismatch again, so development logged the structural warning twice and onRecoverableError fired twice, in both dev and prod.

The server content now stays exactly as the server rendered it while the root is pending, and only the attempt that commits reports. That matches React, which delivers recoverable errors from its commit path.

Why

The root render transaction already rolls a suspended attempt back, so the first part of the fix holds diagnostics until commit. Holding alone was not enough. A probe of each recovery kind at the root showed that the rollback does not restore every recovery:

  • A hydrating rollback unmounts the blocks it created without touching their DOM.
  • childSlot does not journal a first render inside a block created in the same transaction.

So these recoveries left a half-built client subtree in place of the server content while pending:

  • a renderable hole over server text
  • an only-child hole over server text
  • a return slot over server text
  • @for populated versus @empty

Each still reported once, but only because the HYDRATION_REBUILT marks outlived the rollback and silenced the retry. Holding diagnostics without restoring that DOM would have dropped these cases to zero reports.

Changes

packages/octane/src/runtime.ts now treats a root's hydrating attempt as speculative. All new work runs only on mismatch paths.

  • Diagnostics: warnHydrationStructuralMismatch and noteRecoverableHydrationError queue their publish step on the hydrating root transaction's commit list (HydrationCapability.awaitsCommit, a method so bundles that never hydrate drop it). A commit publishes it and rollbackRootRender drops it. Value warnings are deliberately unchanged; see the follow-ups below.
  • DOM: HydrationCapability.save(parent) journals the parent's children through the existing journalRootChildren at every structural recovery site, so rollback restores the server DOM that the retry adopts and reports. These sites are:
    • discard, claimRange and discardServerText
    • leftover items, unadopted text and abandonRoot
    • template and fragment mismatches, and a missing cursor
    • finishRoot and the host text bodies
    • componentSlot's missing range
    • de-opt host tags, @if branch rebuilds and @for @empty swaps
  • Rebuilt marks: HydrationCapability.remember journals HYDRATION_REBUILT and HYDRATION_REBUILT_HOSTS additions, so a rollback forgets them along with the DOM they described.
  • Composition with the try-body hold (fix(octane): drop hydration diagnostics from try bodies caught by their catch arm #1534): a structural warning that a try body's diagnostic hold releases now re-enters logHydrationMismatch instead of logging directly, so it still reaches the root hold. Value warnings pass structural = false and keep their previous behavior.
  • try-clone-thrower test (fix(octane): drop hydration diagnostics from try bodies caught by their catch arm #1534): its catch-only Branch case suspends the root on a promise that never resolved, and asserted that the discarded root attempt reported. It now resolves the promise and asserts nothing reports while pending (the server content is kept), then one report from the attempt that commits. The @pending case is unchanged.
  • Docs: one sentence in the Hydration section of docs/differences-from-react.md.
  • Changeset: octane patch.

Contract: an attempt that suspends reports nothing, and the attempt that commits reports. An attempt that ends in an uncaught error now reports nothing for the recovery it discarded. Before this change it published that recovery's warning and onRecoverableError report anyway.

Validation

Rebased onto 5f354d23e, which brought in #1534's try-body diagnostic hold. Results are marked as before or after that rebase.

  • pnpm format:check (before the rebase); every file changed after it passes pnpm format:files:check
  • pnpm typecheck, on the rebased head. The try-clone-thrower change also passes pnpm typecheck:files.
  • pnpm test: not run in full; the targeted projects below cover the change.
  • targeted tests:
    • New packages/octane/tests/hydration/root-suspended-clone-mismatch.test.ts, with dev and prod compiles. It covers the reported repro, an inserted clone with preserved user input, a nested resolved arm, renderable and only-child holes, fewer list items, an @empty list, and an uncaught error. Each case asserts the server nodes kept by identity while pending, no diagnostics while pending, the final DOM, and reports equal to the same hydration without suspension. All 16 tests fail on main. Removing any one of the commit hold, save, or the remember journaling turns cases red. After the rebase, making a released try-body warning log directly turns RootNestedArm red in dev. All 32 test runs pass on the rebased head.
    • octane + octane-prod Vitest projects: 1299 files and 36,072 tests passed before the rebase. On the rebased head, 1296 of 1303 files passed with the load average around 65–90. Of the 7 failures, try-clone-thrower is the contract change above and passes 52/52 after its update. behavior-root, hydration-ssr-diagnostics, compiler/volar, ssr-suspense and react-hosted/web3-island (a hook timeout) pass when rerun alone in both projects.
    • Every non-octane test file that calls hydrateRoot: 61 files passed (before the rebase).
    • pnpm typecheck:files with the .tsrx fixture passed explicitly.

Bundle bytes over 5f354d23e (benchmarks/bundle-size/run-minimal.mjs, at 6833ab671):

Scenario raw gzip brotli
hydrate-root +833 +230 +309
deferred-hydration +841 +232 +287
root-static +123 +51 +49
cli-spa-starter +20 +7 −38
context +10 +6 +26
suspense-transition +10 +7 +68
root-chained-jsx 0 0 0

The PR bench report was taken before 6833ab671, which moved the root hold onto HydrationCapability and roughly halved the client-only cost (root-static +257 → +123 raw). What client-only bundles still carry is the save call sites in shared mount paths and the hold check in noteRecoverableHydrationError.

There is no timing comparison. No new code runs on happy-path hydration or on the update commit path, and machine load was too high for a meaningful run.

Risk / follow-ups

  • Value repairs at a suspended root are unchanged:

    • Text is rewritten while pending and never reported.
    • The dev attribute warning prints twice.
    • Style patches survive the rollback.

    Holding value warnings now would lose the style report, so it needs the writes journaled first. This is filed separately.

  • Some structural rebuilds never call onRecoverableError, even without suspension: the empty @if branch, the @for @empty swaps, and the de-opt host-tag mismatch. This is filed separately.

  • Overlap with an unmerged sibling fix: a fix for the same defect in resolved @try arms uses save call sites at the same places. Whichever change lands second merges the save bodies: the arm's snapshot plus the root journal.

  • Order of messages: structural warnings now print at the root's commit rather than mid-render, which can reorder them against other render-time console output.

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
Changes core hydration rollback, DOM journaling, and when recoverable errors fire; scoped to mismatch/suspended-root paths but affects dev and prod client behavior.

Overview
Fixes double structural hydration warnings and duplicate onRecoverableError callbacks when the root suspends mid-hydration after a mismatched rebuild on a discarded attempt.

Diagnostics for structural mismatches and recoverable errors now defer to the hydrating root transaction's commit via HydrationCapability.awaitsCommit; rollback drops queued publishes. Value warnings stay immediate.

DOM at structural recovery sites calls HydrationCapability.save so rollback restores server markup (holes, list/@empty shape, etc.) while pending instead of leaving a half-built client subtree. remember journals HYDRATION_REBUILT marks so a rolled-back attempt does not silence the retry.

Try-body diagnostic releases route structural warnings back through logHydrationMismatch so they still participate in the root hold. Adds root-suspended-clone-mismatch tests, updates try-clone-thrower expectations, documents React-aligned commit-time reporting in differences-from-react.md, and bumps octane with a small hydrate-bundle cost on mismatch paths only.

Reviewed by Cursor Bugbot for commit 1d1e431. Bugbot is set up for automated code reviews on this repo. Configure here.

A root with no Suspense boundary whose first hydrating attempt rebuilt a
mismatched clone and then suspended published that attempt's diagnostics,
although the root render transaction discarded the attempt. The retry over
the restored server DOM then reported the same mismatch again: two dev
structural warnings and two onRecoverableError calls.

Holding diagnostics alone would have lost reports. A hydrating rollback
keeps the DOM of blocks it created, and childSlot does not journal a first
render inside a block created in the same transaction. So the renderable and
only-child hole, return-slot text, and @for @empty recoveries left a
half-built client subtree in place of the server content while the root was
pending. The HYDRATION_REBUILT marks then silenced the retry.

A root's hydrating attempt is now speculative:
- Structural warnings and onRecoverableError reports wait on the root
  transaction's commit list. The attempt that commits publishes them, and a
  rollback drops them.
- HydrationCapability.save journals the parent's children at every
  structural recovery site through journalRootChildren. Rollback then
  restores the server DOM that the retry adopts and reports.
- Rebuilt-range and rebuilt-host marks are journaled, so a rollback forgets
  them with the DOM they described.
- A structural warning that a try body's diagnostic hold releases re-enters
  logHydrationMismatch, so it reaches the root hold instead of logging
  directly. Value warnings stay outside the root hold: rollback does not
  undo every value repair, so their retry may not repeat them.

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
The try-clone-thrower case for a catch-only boundary whose body suspends
let the suspension reach the root and asserted that the discarded root
attempt reported the rebuilt clone while the promise never resolved. A
suspended root attempt now reports only if it commits, so resolve the
promise and assert the server content stays and nothing reports while
pending, then one report from the attempt that commits. The @pending
boundary case, which commits the root around its suspended arm, is
unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm marked this pull request as ready for review October 2, 2026 08:55
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

No benchmark report for this commit yet: PR bench is still running or skipped this change.

CI job durations

⚪ No job outside the range of recent main runs.

Compares the CI run for 1d1e4317b (run) with the last 5 successful main push runs. A job is only slower or faster outside the whole main range, by at least 10% and 15s. Job time excludes runner setup.

job main median main range this PR Δ
wall clock (first job start to last job end) 13m 32s 11m 55s–15m 07s 12m 25s −1m 07s (−8%) ⚪ within noise
total job time 149m 29s 134m 18s–156m 28s 138m 45s −10m 44s (−7%) ⚪ within noise
All 26 timed jobs
job main median main range this PR Δ
lint checks 8m 01s 7m 46s–9m 37s 8m 24s +23s (+5%) ⚪ within noise
React parity shard (1/4) 10m 55s 10m 45s–12m 00s 11m 11s +16s (+2%) ⚪ within noise
heavy integration (package builds, eval corpus, runtime loaders, Astro) 5m 43s 5m 27s–5m 45s 5m 58s +15s (+4%) ⚪ within noise
example apps (2/3) 3m 43s 3m 38s–3m 49s 3m 53s +10s (+4%) ⚪ within noise
Lynx compatibility 1m 32s 1m 29s–2m 04s 1m 38s +6s (+7%) ⚪ within noise
validate publishable packages 4m 16s 3m 51s–5m 00s 4m 20s +4s (+2%) ⚪ within noise
classify changeset release 13s 13s–15s 14s +1s (+8%) ⚪ within noise
React parity checks 11s 10s–12s 12s +1s (+9%) ⚪ within noise
typecheck 3s 3s–4s 3s ±0s (±0%) ⚪ within noise
lint 3s 3s–4s 3s ±0s (±0%) ⚪ within noise
test (24) 3s 3s–4s 3s ±0s (±0%) ⚪ within noise
CI provenance 3s 3s–4s 3s ±0s (±0%) ⚪ within noise
example apps (1/3) 3m 12s 3m 06s–3m 19s 3m 11s −1s (−1%) ⚪ within noise
examples 3s 3s–4s 2s −1s (−33%) ⚪ within noise
test shard (Node 24, 1/4) 11m 23s 10m 36s–13m 13s 11m 19s −4s (−1%) ⚪ within noise
website integration suite 5m 56s 5m 44s–7m 00s 5m 50s −6s (−2%) ⚪ within noise
Three compatibility 2m 44s 2m 38s–3m 48s 2m 38s −6s (−4%) ⚪ within noise
example apps (3/3) 3m 38s 3m 19s–3m 41s 3m 27s −11s (−5%) ⚪ within noise
React parity shard (2/4) 10m 30s 9m 52s–11m 18s 10m 16s −14s (−2%) ⚪ within noise
test shard (Node 24, 3/4) 10m 02s 9m 24s–10m 50s 9m 46s −16s (−3%) ⚪ within noise
test shard (Node 24, 4/4) 11m 06s 10m 21s–13m 56s 10m 45s −21s (−3%) ⚪ within noise
heavy integration (browser - chromium) 12m 12s 10m 58s–12m 54s 11m 48s −24s (−3%) ⚪ within noise
React parity shard (4/4) 11m 19s 10m 08s–12m 06s 10m 55s −24s (−4%) ⚪ within noise
React parity shard (3/4) 10m 36s 10m 08s–12m 02s 9m 41s −55s (−9%) ⚪ within noise
test shard (Node 24, 2/4) 12m 09s 10m 38s–14m 29s 11m 04s −1m 05s (−9%) ⚪ within noise
typecheck checks 8m 20s 1m 56s–9m 11s 2m 01s −6m 19s (−76%) ⚪ within noise

…dles

noteRecoverableHydrationError is reachable from shared mount paths, so the
free functions behind the root attempt's commit hold shipped in bundles
that never hydrate. Make the hold a HydrationCapability method,
awaitsCommit, reached through currentHydration like the try-body hold's
`holds`. A diagnostic in a root's hydrating attempt always runs under a
hydration capability, and bundles that never hydrate drop the class.

root-static: +257 -> +123 raw, +87 -> +51 gzip over main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm added a commit that referenced this pull request Oct 2, 2026
…e mismatches once (#1556)

* fix(hydration): report a suspended root's rebuilt mismatch once

A root with no Suspense boundary whose first hydrating attempt rebuilt a
mismatched clone and then suspended published that attempt's diagnostics,
although the root render transaction discarded the attempt. The retry over
the restored server DOM then reported the same mismatch again: two dev
structural warnings and two onRecoverableError calls.

Holding diagnostics alone would have lost reports. A hydrating rollback
keeps the DOM of blocks it created, and childSlot does not journal a first
render inside a block created in the same transaction. So the renderable and
only-child hole, return-slot text, and @for @empty recoveries left a
half-built client subtree in place of the server content while the root was
pending. The HYDRATION_REBUILT marks then silenced the retry.

A root's hydrating attempt is now speculative:
- Structural warnings and onRecoverableError reports wait on the root
  transaction's commit list. The attempt that commits publishes them, and a
  rollback drops them.
- HydrationCapability.save journals the parent's children at every
  structural recovery site through journalRootChildren. Rollback then
  restores the server DOM that the retry adopts and reports.
- Rebuilt-range and rebuilt-host marks are journaled, so a rollback forgets
  them with the DOM they described.
- A structural warning that a try body's diagnostic hold releases re-enters
  logHydrationMismatch, so it reaches the root hold instead of logging
  directly. Value warnings stay outside the root hold: rollback does not
  undo every value repair, so their retry may not repeat them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(hydration): report a root-suspending clone when the root commits

The try-clone-thrower case for a catch-only boundary whose body suspends
let the suspension reach the root and asserted that the discarded root
attempt reported the rebuilt clone while the promise never resolved. A
suspended root attempt now reports only if it commits, so resolve the
promise and assert the server content stays and nothing reports while
pending, then one report from the attempt that commits. The @pending
boundary case, which commits the root around its suspended arm, is
unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* perf(hydration): keep the root diagnostic hold out of client-only bundles

noteRecoverableHydrationError is reachable from shared mount paths, so the
free functions behind the root attempt's commit hold shipped in bundles
that never hydrate. Make the hold a HydrationCapability method,
awaitsCommit, reached through currentHydration like the try-body hold's
`holds`. A diagnostic in a root's hydrating attempt always runs under a
hydration capability, and bundles that never hydrate drop the class.

root-static: +257 -> +123 raw, +87 -> +51 gzip over main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(hydration): keep a suspended root's server values and report value mismatches once

A root with no Suspense boundary whose first hydrating attempt repaired a
value mismatch and then suspended behaved differently from a hydration that
never suspends:

- Text: the htext/htextSwap nodeValue writes were not journaled, so the
  server text showed the client value while pending. The retry found the
  text already matching, so the mismatch never reached onRecoverableError
  and development logged no warning.
- Style and class: hydration's applyStyle and flushClassWrites writes were
  not journaled either, so a style patch survived the rollback.
- Attribute and dangerouslySetInnerHTML: the discarded attempt and the
  retry each logged the development warning.

In a root's hydrating attempt, HydrationCapability.journalRepair now journals
each server text, class and style value before a repair overwrites it, so
the rollback restores what the retry adopts and reports. Freshly cloned
nodes are skipped: they hold the client template's values, and restoring
one left a visible placeholder and a false text report on the retry.
Attribute setters already journal through journalAttr. With every value
repair undone on rollback, logHydrationMismatch now holds value and
kept-server warnings for the root commit as well as structural ones, still
after a try body's hold.

The journal restored a removed namespaced attribute with setAttribute,
which recreated `xlink:href` without its namespace. That affected client
root updates too. setAttribute now journals the namespace it already
computed, and rollback uses setAttributeNS, without pulling attrNamespace
into every bundle.

Stacked on #1551.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
…dration-mismatch

# Conflicts:
#	docs/differences-from-react.md
#	packages/octane/src/runtime.ts
@trueadm
trueadm merged commit acb4e03 into main Oct 2, 2026
29 checks passed
@trueadm
trueadm deleted the fix/root-suspended-hydration-mismatch branch October 2, 2026 12:16
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