Repository navigation
fix(hydration): report a suspended root's rebuilt mismatch once - #1551
Merged
Merged
Conversation
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]>
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
marked this pull request as ready for review
October 2, 2026 08:55
Contributor
Benchmark reportNo 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 Compares the CI run for
All 26 timed jobs
|
…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]>
9 tasks done
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
2 of 5 tasks
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 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
onRecoverableErrorfired 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:
childSlotdoes 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:
@forpopulated versus@emptyEach still reported once, but only because the
HYDRATION_REBUILTmarks 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.tsnow treats a root's hydrating attempt as speculative. All new work runs only on mismatch paths.warnHydrationStructuralMismatchandnoteRecoverableHydrationErrorqueue their publish step on the hydrating root transaction'scommitlist (HydrationCapability.awaitsCommit, a method so bundles that never hydrate drop it). A commit publishes it androllbackRootRenderdrops it. Value warnings are deliberately unchanged; see the follow-ups below.HydrationCapability.save(parent)journals the parent's children through the existingjournalRootChildrenat every structural recovery site, so rollback restores the server DOM that the retry adopts and reports. These sites are:@ifbranch rebuilds and@for@emptyswapsHydrationCapability.rememberjournalsHYDRATION_REBUILTandHYDRATION_REBUILT_HOSTSadditions, so a rollback forgets them along with the DOM they described.logHydrationMismatchinstead of logging directly, so it still reaches the root hold. Value warnings passstructural = falseand keep their previous behavior.try-clone-throwertest (fix(octane): drop hydration diagnostics from try bodies caught by their catch arm #1534): its catch-onlyBranchcase 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@pendingcase is unchanged.docs/differences-from-react.md.octanepatch.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
onRecoverableErrorreport 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 passespnpm format:files:checkpnpm typecheck, on the rebased head. Thetry-clone-throwerchange also passespnpm typecheck:files.pnpm test: not run in full; the targeted projects below cover the change.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@emptylist, 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 onmain. Removing any one of the commit hold,save, or therememberjournaling turns cases red. After the rebase, making a released try-body warning log directly turnsRootNestedArmred in dev. All 32 test runs pass on the rebased head.octane+octane-prodVitest 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-throweris the contract change above and passes 52/52 after its update.behavior-root,hydration-ssr-diagnostics,compiler/volar,ssr-suspenseandreact-hosted/web3-island(a hook timeout) pass when rerun alone in both projects.hydrateRoot: 61 files passed (before the rebase).pnpm typecheck:fileswith the.tsrxfixture passed explicitly.Bundle bytes over
5f354d23e(benchmarks/bundle-size/run-minimal.mjs, at6833ab671):The PR bench report was taken before
6833ab671, which moved the root hold ontoHydrationCapabilityand roughly halved the client-only cost (root-static+257 → +123 raw). What client-only bundles still carry is thesavecall sites in shared mount paths and the hold check innoteRecoverableHydrationError.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:
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@ifbranch, the@for@emptyswaps, 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
@tryarms usessavecall sites at the same places. Whichever change lands second merges thesavebodies: 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
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 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
onRecoverableErrorcallbacks 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.saveso rollback restores server markup (holes, list/@emptyshape, etc.) while pending instead of leaving a half-built client subtree.rememberjournalsHYDRATION_REBUILTmarks so a rolled-back attempt does not silence the retry.Try-body diagnostic releases route structural warnings back through
logHydrationMismatchso they still participate in the root hold. Addsroot-suspended-clone-mismatchtests, updatestry-clone-throwerexpectations, documents React-aligned commit-time reporting indifferences-from-react.md, and bumpsoctanewith 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.