Repository navigation
fix(hydration): keep a suspended root's server values and report value mismatches once - #1556
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]>
…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]>
…e 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]>
Benchmark report
Compares js-framework: 1k/10k row operations (ms, lower is better)All 20 timed operations (20 within noise)
Application bundle size (bytes)
8 other measured values are unchanged. Public-import reachability bundles (bytes)
36 other measured values are unchanged. CI job durations
Compares the CI run for
Not compared (skipped, failed, or not run on this pull request): Lynx compatibility (minimum), heavy integration (runtime-loaders), Three compatibility (minimum r156), Three compatibility (current), heavy integration (browser), heavy integration (eval-corpus), Lynx compatibility (current), test shard (Node 22.22.2, 1/4), heavy integration (package-builds), heavy integration (astro), test shard (Node 22.22.2, 2/4), test shard (Node 22.22.2, 3/4), test shard (Node 22.22.2, 4/4), test (22). All 26 timed jobs
|
…ttempt rebuilt a mismatch (#1560) * fix(hydration): keep server values in a suspended @Try arm and report once at commit A resolved @Try arm (server emitted oct-suspense:N) hydrates speculatively: when its first attempt suspends, the attempt is discarded and a later one adopts the same server nodes. An attempt that repaired a text or attribute value before suspending wrote the client value into the server's markup while the arm was still pending, and queued the text warning on a capability that the suspension dropped. The committing attempt then found the value already matching, so the mismatch never reached onRecoverableError or the dev warning. The arm's HydrationCapability is now speculative. Before it overwrites a server text value, attribute, class or style, it records the server value, and rollback() restores them when the attempt suspends or throws. Nodes cloned fresh by structural recovery hold client template values and are skipped. Value warnings (attribute, class, style, kept dangerouslySetInnerHTML) are held until the attempt settles. A nested arm that commits inside an enclosing speculative attempt hands its records and pending warnings to that attempt. Co-Authored-By: Claude Opus 5.5 <[email protected]> * perf(hydration): read the repaired server value only in a speculative attempt Move the speculative check and the server-value read into HydrationCapability.repaired(), so each repair site is one call. A non-speculative hydration no longer reads the class or style attribute at all on the mismatch path, and hydrate-root / deferred-hydration shrink by 87 raw bytes. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(hydration): keep a suspended @Try arm's server content when its attempt rebuilt a mismatch A resolved @Try arm (oct-suspense:N) whose first hydrating attempt rebuilt a mismatched template clone and then suspended removed the server node while the attempt was discarded, left the arm blank while pending, and reported the structural mismatch twice (dev warning and onRecoverableError, dev and prod): the retry found only the range's close marker and reported again. A speculative attempt now keeps one undo list. save(parent) snapshots a parent's children once before structural recovery changes them (the same sites #1556 journals for roots, plus the de-opt reconcile); remember() makes HYDRATION_REBUILT marks undoable; #1544's value repairs push restore steps onto the same list. settle() hands the list to an enclosing speculative attempt and rollback() replays it newest first. Any failed attempt rolls back and drops its held diagnostics, so the attempt that commits reports each mismatch once. #1544's heldWarnings/repairs log fold into this list and #1534's hold. collectRootRange/restoreRootRange are shared with journalRootRange, and a dormant island's staleServerValues now carries to retries. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(hydration): undo de-opt children a suspended @Try arm inserted or moved reconcileDeoptChildren recorded a speculative snapshot of a server host only when it removed a child. Filling an empty server host, or inserting and moving children in its ordering pass, journaled only for the root, so a resolved @Try arm that hit those paths and then suspended left client-built children in the server markup while pending. Record the host before both, through a cold helper that does nothing outside a hydrating attempt or for a fresh host. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(hydration): skip restoring a range whose bounds left their parent The speculative arm's undo called restoreRootRange without the check that journalRootRange makes first: when either bound is no longer in the parent, the snapshot owns no range there, and walking to a bound that is gone sweeps the parent's later siblings and then inserts before a detached anchor. Move the check into restoreRootRange so both callers share it. Recovery cannot detach an arm's own bounds in balanced markup; the regression simulates an outside mutation during the suspended attempt. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
Builds on #1551's model, where a root's hydrating attempt reports only if it commits, and extends it to value repairs. 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:
onRecoverableError, no dev warning)dangerouslySetInnerHTMLxlink:hrefremoved, then rolled backgetAttributeNS→ null), so the retry saw nothingWhy
htext/htextSwap,applyStyle, andflushClassWriteswrote repaired values without journaling them. fix(hydration): report a suspended root's rebuilt mismatch once #1551's rollback therefore couldn't restore them, and fix(hydration): report a suspended root's rebuilt mismatch once #1551 had to keep value warnings out of its commit hold: its comment notes that the retry "may not repeat the warning".rollbackTransitionJournalrestored a removed attribute withsetAttribute(qualifiedName, value), which creates a non-namespacedxlink:href. This also affects client root updates that suspend, not just hydration.Changes
HydrationCapability.journalRepair(node, attribute | null)runs only wheninRootHydrationAttempt()is true. It journals the server text,class, orstylebefore a repair overwrites it. Freshly cloned nodes are skipped. Restoring one would leave a clone that fix(hydration): report a suspended root's rebuilt mismatch once #1551 hasn't removed showing its template placeholder, and the retry would report a false text mismatch; a test covers this.logHydrationMismatchnow waits for the root commit for every warning, after the try-body hold (fix(octane): drop hydration diagnostics from try bodies caught by their catch arm #1534). Thestructuralflag is gone. The text recoverable report already goes through fix(hydration): report a suspended root's rebuilt mismatch once #1551'snoteRecoverableHydrationErrorhold.setAttributepasses the namespace it already computes tojournalAttr, which records[ns, name]only for namespaced names. Rollback usessetAttributeNSfor those. CallingattrNamespaceinside rollback instead cost +320 raw / +125 gzip on every client bundle, so I avoided it.docs/differences-from-react.md.Validation
tests/hydration/root-suspended-value-mismatch.test.ts, 56 tests ×octane/octane-prod, dev and prod compiles. It covers text, sibling text, attribute, three style forms, class, raw HTML,@tryarms inside the root, xlink removal and change, a retry that suspends again, a rebuilt@ifbranch (parity with never suspending), a rebuilt hole clone, and a caught try body (fix(octane): drop hydration diagnostics from try bodies caught by their catch arm #1534 order). Also a client-update xlink rollback case inhost-attribute-updates.test.ts.mainbase, 46 of the first 100 failed.root-suspended-clone-mismatch,try-clone-thrower), plusmismatch-value,host-attribute-updates,style-transaction-rollback: 12 files, 282 tests pass.octane+octane-prodon the pre-stack revision of this change (same journaling, its own hold helpers): 1303 files, all green after a fix to the test's own site lookup. The 59 binding test files that callhydrateRootpass.octane+octane-prodVitest projects on this stacked head (e6f0273): 1305 files, 36265 tests pass. Repo-widepnpm test,pnpm typecheckandpnpm format:checkare left to CI.pnpm typecheck:fileson runtime, the new test, and its fixture.host-attribute-updates.tsrxkeeps the 7 implicit-anyerrors already onmain; the newPendingSpriteis typed.pnpm format:files:checkon all changed files;pnpm syncis clean.Bundle: the CI benchmark report covers #1551 and this PR together. Subtracting #1551's own report gives this PR's share: client bundles about +56–68 raw / +27–46 gzip (the journal's namespace encoding; e.g.
octane-tsrx+66 raw,octane-jsx+68 raw);hydrate-root+387 raw / +95 gzip, on top of #1551's +833 / +230; server scenarios unchanged. No timing verdicts moved: all 20 js-framework operations are within noise. The new code runs only on hydration-mismatch and rollback paths.Risk / follow-ups
hydrateRoot, but after any structural warnings from the same pass. An attempt that ends in an uncaught error now drops its value warnings, matching fix(hydration): report a suspended root's rebuilt mismatch once #1551's contract.renderInitialSuspenseHydration) are a separate fix, cb7673c. It will conflict mechanically at the call sites next tojournalRepair.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, journaling, and error reporting for roots that suspend during hydrate; behavior is well-tested but touches sensitive DOM recovery paths.
Overview
When a root hydrates without a Suspense boundary and the first attempt suspends, mismatch recovery no longer leaves half-built client DOM or repaired text/style/class on screen. Structural changes are journaled (
HydrationCapability.save,journalRepair,remember) and rolled back with the attempt; only the attempt that commits publishes dev warnings andonRecoverableError(viaawaitsCommit/inRootHydrationAttempt).Value mismatches that used to be patched then hidden (or never reported for text) now stay as server values while pending and are reported once when hydration finishes. Dev hydration warnings follow the same commit gate.
Rollback restores namespaced attributes (
xlink:href) withsetAttributeNSafter journaling[namespace, name].Docs and new hydration/client-update tests cover structural rebuilds, value repairs, xlink, and parity with non-suspending hydration.
Reviewed by Cursor Bugbot for commit e6f0273. Bugbot is set up for automated code reviews on this repo. Configure here.