Repository navigation
fix(hydration): keep a suspended @try arm's server content when its attempt rebuilt a mismatch - #1560
Conversation
… 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]>
…ue-repair # Conflicts: # packages/octane/src/runtime.ts
… 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]>
…ue-repair # Conflicts: # docs/differences-from-react.md # packages/octane/src/runtime.ts
…ttempt 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]>
Benchmark report
Compares js-framework: 1k/10k row operations (ms, lower is better)All 20 timed operations (20 within noise)
Application bundle size (bytes)
7 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
|
… 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]>
|
On the bench report: most of the hydrate-root and deferred-hydration growth (+953 raw / +310–324 gzip vs Measured with
The client-only and application bundles in the report move by a few bytes in either direction. The js-framework timings are all within noise. 🤖 Addressed by Claude Code |
…uctural-rollback # Conflicts: # docs/differences-from-react.md # packages/octane/src/runtime.ts
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Detached arm bounds skip rollback guard
- Added the same parentNode guard from journalRootRange to the speculative save() undo closure, so rollback skips restoreRootRange when the arm's start or end marker has been detached from parent by removeHydrationRange.
Or push these changes by commenting:
@cursor push 9ffe9fa95f
Preview (9ffe9fa95f)
diff --git a/packages/octane/src/runtime.ts b/packages/octane/src/runtime.ts
--- a/packages/octane/src/runtime.ts
+++ b/packages/octane/src/runtime.ts
@@ -18729,7 +18729,14 @@
const before = ranged ? arm.startMarker : null;
const after = ranged ? arm.endMarker : null;
const nodes = collectRootRange(parent, before, after);
- (this.undo ??= []).push(() => restoreRootRange(parent, before, after, nodes));
+ (this.undo ??= []).push(() => {
+ if (
+ (before !== null && (STAGED_DOM?.view(before) ?? before).parentNode !== parent) ||
+ (after !== null && (STAGED_DOM?.view(after) ?? after).parentNode !== parent)
+ )
+ return;
+ restoreRootRange(parent, before, after, nodes);
+ });
}
/**You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 85f67f3. Configure here.
|
Bugbot Autofix prepared a fix for the issue found in the latest run.
Or push these changes by commenting: Preview (217d9c548e)diff --git a/packages/octane/src/runtime.ts b/packages/octane/src/runtime.ts
--- a/packages/octane/src/runtime.ts
+++ b/packages/octane/src/runtime.ts
@@ -33090,6 +33090,10 @@
// so just build + append each child. Skips the keyed-match Map / Set / reorder
// bookkeeping below, which is the hot path for large initial mounts.
if (firstChild === null) {
+ {
+ const hydration = activeHydration();
+ if (hydration !== null && !hydration.isFresh(el)) hydration.save(el);
+ }
for (let i = 0; i < next.length; i++) {
const node = reconcileDeoptNode(null, next[i], ownerBlock, childNs);
if (node !== null) {
@@ -33194,6 +33198,10 @@
// Advance through owned live children once. Indexed childNodes reads restart
// native list walks after each insertion; foreign ranges also must not make
// every survivor rescan the preceding siblings.
+ {
+ const hydration = activeHydration();
+ if (hydration !== null && !hydration.isFresh(el)) hydration.save(el);
+ }
let cursor: Node | null = getFirstChild(el);
for (let i = 0; i < result.length; i++) {
const want = result[i];You can send follow-ups to the cloud agent here. |
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]>
|
The Bugbot Autofix branch ( 🤖 Addressed by Claude Code |
…ition #1560 rolls back a speculative Suspense attempt's structural recovery, so a suspended attempt's rebuilt root no longer survives into the next attempt. Take main's InitialSuspenseHydration.stale, and drop this branch's set of client-built nodes shared across attempts, which is now unused. Co-Authored-By: Claude Opus 5.5 <[email protected]>


Summary
A resolved
@tryarm (the server emittedoct-suspense:N) whose first hydrating attempt rebuilt a mismatched template clone and then suspended had three symptoms:onRecoverableErrorcalls, in dev and prod.adoptmismatch path removed the server node throughdiscardCursor, and the attempt was then discarded.The same happened at every structural recovery site reached during a speculative attempt.
The contract, which matches the existing "suspended initial adoption leaves its real server arm untouched" design:
Changes
This adds one mechanism that #1544's value repairs now share. It folds #1544's separate
repairslog andheldWarningsinto the single undo list and #1534's hold.HydrationCapability.speculativekeeps oneundolist:save(parent)snapshots a parent's children once, before structural recovery changes them. It is called at the same ~20 recovery sites that fix(hydration): keep a suspended root's server values and report value mismatches once #1556 journals for roots, plus the de-opt children reconcile.remember(set, node)makesHYDRATION_REBUILT(_HOSTS)marks undoable.repaired(target, name)value records now push restore steps onto the same list.settle(outer)passes the list to an enclosing speculative attempt;rollback()replays it newest first.collectRootRange/restoreRootRangeare factored out ofjournalRootRange, so the root journal and the arm undo restore ranges the same way.renderInitialSuspenseHydration: on success it runs class writes, then text warnings, thensettle. Any failure rolls back, andreleaseDiagnostics(diagnostics, failed)drops the attempt's held diagnostics. The attempt that commits, or the catch arm adopted over the restored server arm, reports instead.heldWarnings,warnHeldHydrationMismatch, therepairstriples and the text-warning merge. Value warnings andonRecoverableErrorride fix(octane): drop hydration diagnostics from try bodies caught by their catch arm #1534's module hold, which composes with fix(hydration): keep a suspended root's server values and report value mismatches once #1556's rootawaitsCommit.InitialSuspenseHydration.stalecarries a dormantHydrateisland'sstaleServerValuesto retries, which run outside the activation.GateEmptyListandGateLongerList.tests/hydration/suspended-clone-mismatch.test.tsand its fixture, compiled dev and prod. Cases: the reported repro; a clone inserted before the arm suspended, with an adopted input's identity and draft kept; and a nested arm that rebuilt and committed inside an enclosing arm that suspends. Each case compares against a non-suspending control hydration.try-clone-thrower.test.ts: the@try+@pendingvariant of "reports a template clone that suspends" now asserts the commit-time contract, which fix(hydration): keep a suspended root's server values and report value mismatches once #1556 already gave the boundary-less variant.docs/differences-from-react.md. Changeset:octanepatch.Validation
suspended-clone-mismatch: all cases fail on the base runtime and pass here.Mutations of settle-merge,
remember, fresh-node removal and the hold each turn a new or existing test red.Targeted,
octane+octane-prod:suspended-clone-mismatch,suspended-arm-value-mismatch,try-clone-thrower,mismatch-unadoptable-range,root-suspended-clone-mismatch,root-suspended-value-mismatch,initial-suspense-hydrate. 374/374 pass.Full
octane+octane-prod(--testTimeout=60000, load average ~90): 36,605 passed, 4 failed. All four were load timeouts inbehavior-root,compiler/volar,compiler/typescript-text-inference,hydration-ssr-diagnosticsandreact-hosted/web3-island, and those files pass alone. The remainingbehavior-roottimeout ("attaches to existing DOM…") also times out on fix(hydration): keep server values in a suspended @try arm and report once at commit #1544's head runtime at the same load.pnpm typecheck:fileson the changed.ts/.tsrxfiles, andpnpm format:files:checkon the changed files: clean.Bundle bytes for the merged mechanism, measured before rebasing onto current main, vs main
5f354d23e:The CI-gated budgets pass.
There is no wall-clock A/B: machine load average was 43–93. The happy path only gains a flag write and a
settlecall per resolved boundary.Risk / follow-ups
pnpm format:checkand the repo-widepnpm typecheckwere not run locally; CI covers them.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
High Risk
Touches core hydration rollback, DOM restoration, and recoverable-error timing for Suspense arms—bugs could leave wrong markup visible or double-report mismatches.
Overview
Fixes resolved
@try/ Suspense arms whose first hydrating pass rebuilds a structural mismatch and then suspends: the pending UI now keeps the original server DOM (same nodes, including user input), and mismatch /onRecoverableErrorfire only once when the attempt that actually commits runs.HydrationCapabilityreplaces the separaterepairs/heldWarningspath with a singleundostack for speculative attempts:save(parent)snapshots children before mismatch recovery or de-opt reconcile changes them;repaired()records value restores;rollback()replays undo newest-first on suspend/failure;settle()merges into an outer speculative pass. SharedcollectRootRange/restoreRootRangealign root journaling with arm rollback. De-opt child reconcile callssaveDeoptChildrenand skips deferred root removals while speculative.renderInitialSuspenseHydrationrolls back recovery on failure, flushes text warnings before settle, and alwaysreleaseDiagnostics(diagnostics, failed)so discarded attempts do not publish. Docs and a patch changeset describe the React-aligned reporting contract; newsuspended-clone-mismatchtests (dev/prod) cover clones, nested arms, de-opt lists, and torn arm bounds.Reviewed by Cursor Bugbot for commit 7e8e8ee. Bugbot is set up for automated code reviews on this repo. Configure here.