Repository navigation
fix(octane): stop hydration looping when stale server content follows an early-bound host - #1751
Conversation
… an early-bound host An early host binding records its host's server neighbors as a site fingerprint. When hydration mismatch recovery removed stale server content beside the host, the lease looked moved at commit. The commit rolled back, which restored the stale node, and retried in a microtask, forever. Hydration's save() hook, which runs before recovery changes a parent's children, now marks that parent. A host whose recorded neighbor was removed from a repaired parent keeps its site. Any other neighbor change still refuses the lease at hydrateRoot. Fixes #1743 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Benchmark report
Compares js-framework: 1k/10k row operations
All 20 timed operations (19 without a verdict)
All 64 work counters are unchanged. Application bundle size (bytes)
50 other measured values are unchanged. Public-import reachability bundles (bytes)
99 other measured values are unchanged. |
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: Lease exemption outlives the hydration
- Journaled the repairedServerParents.add(parent) call in save() for both root hydration rollback (journalUndo) and speculative attempt rollback (this.undo), matching the existing remember() pattern, so rolled-back attempts no longer leave stale exemptions; commit-time cleanup was not added because the exemption is still needed when render cleanups validate the lease during spliceOffscreenCapture.
Or push these changes by commenting:
@cursor push 8d4923de30
Preview (8d4923de30)
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
@@ -19420,7 +19420,14 @@
*/
save(parent: Node): void {
// An early-bound host losing a server neighbor here has not moved.
- repairedServerParents.add(parent);
+ // Journal the exemption so a rolled-back attempt does not leave a stale
+ // entry that a later hydrateRoot on the same container could misread.
+ if (!repairedServerParents.has(parent)) {
+ repairedServerParents.add(parent);
+ const cleanup = () => repairedServerParents.delete(parent);
+ if (inRootHydrationAttempt()) journalUndo(cleanup);
+ if (this.speculative) (this.undo ??= []).push(cleanup);
+ }
if (inRootHydrationAttempt()) journalRootChildren(parent);
if (!this.speculative || (this.saved ??= new Set()).has(parent)) return;
this.saved.add(parent);You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 272fd15. Configure here.
…them A parent repaired by an earlier hydration stayed marked, so a later hydrateRoot on the same container treated an externally removed host neighbor as a repair and accepted the lease. hydrateRoot now clears a leased host's parent before validating the lease. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The hydrateRoot reset added a native parentNode read outside the staged-DOM inventory and pushed hydrate-root past its byte budget. Scope the exemption in the lease instead: a repaired parent excuses a detached neighbor only while a hydration holds the lease or after it retired it. The hydrateRoot gate runs before the claim, so it stays strict, and the runtime keeps only the one-line mark in HydrationCapability.save(). Co-Authored-By: Claude Opus 5.5 <[email protected]>


Summary
Fixes #1743.
When an early host binding (
adoptBindings) was installed and the server node directly after its host was stale content,hydrateRootreturned but the nextact()never did. Hydration now behaves as it does when no binding is installed: it removes the stale content, reports one recoverable error, keeps the adopted host, hands the binding off, and runs the layout effect.Root cause. The host lease's
valid()indom-bindings.tsrecords the host's server neighbors as a site fingerprint. Mismatch recovery removed the stale neighbor, so at commitcurrentPresentation()saw an invalid lease.commitRootRendersthen rolled back the attempt, which put the stale node back, and calledretryPresentations(). The root retry queuedadopt()in a microtask, the next attempt removed the node again, and the cycle repeated forever. Because each retry is a microtask, Vitest's timeout never fired either.This happened on two recovery paths, which I confirmed on
main:settleClaim(stale content at the end of the host component's range), as in the issue's repro;finishRoot(a root-level or in-place host, or one inside@if,@foror a fragment, followed by a stale root remainder).Changes
HydrationCapability.save(parent)is the documented hook that runs before mismatch recovery changes a parent's children. It now addsparentto a newrepairedServerParentsWeakSet. That WeakSet lives indom-binding-claims.ts, the module already shared by early bindings and hydration.The host lease's
valid()checks each side withadjacent(recorded, previous). That check passes in two cases:The ancestry, document,
data-octane-bindingsand still-attached-neighbor checks are unchanged. The helper is allocated only when a lease is requested.A first version tolerated any detached neighbor. It let an externally damaged site, such as a removed range marker, through the
hydrateRootgate and into a new loop. Tying the exemption to the recovery hook keeps the gate strict.The lease honors a repair mark only while a hydration holds it (
ownerset) or after that hydration has retired it.hydrateRootchecks the lease before claiming it, so a repair left from an earlier hydration of the same container cannot excuse a later external change (raised by Bugbot). The runtime change stays a single line insave(), inside thehydrate-rootbyte budget.Validation
pnpm format:check: not run repo-wide.pnpm format:files:checkpasses on the changed files.pnpm typecheck: not run repo-wide.pnpm typecheck:fileson the changed files reports no new errors. The threebehavior-root.test.tsdiagnostics it prints are unchanged lines that also exist onmain.pnpm test: left to CI.--project octane):behavior-root.test.ts,binding-handoff.test.tsandbehavior-handoff-bundle.test.ts, 339 passing. The new cases also pass under--project octane-prod.behavior-root.test.ts: dev and prod × nested and root host × {matching, stale, removed by something other than hydration}. It asserts that there is no uncaught error, exactly one recoverable error for stale content, that the stale node is removed, the button and its child keep their identity, the layout effect runs once, the early source unsubscribes once and a later early publish does not write, and that a laterroot.renderupdates the same button. A render watchdog turns a non-converging hydration into a failed assertion instead of a hung worker.hydrateRootmust refuse with Fix user-app starter verifier CI timeout #77. It fails without the claim condition.repairedServerParentscondition fails the 4 "removed" cases, becausehydrateRootno longer refuses with Fix user-app starter verifier CI timeout #77. The existing reorder refusal ('propagates a rejected external range readiness…') still fails if neighbor adjacency is dropped.@if/@for/fragment/in-place root hosts. With the early binding, each now ends the same way as the no-binding control.Risk / follow-ups
hydrateRootgate, as before.TypeError.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 hydration mismatch recovery interaction with early binding lease validation—a sensitive commit/handoff path—but the scope is narrow and heavily regression-tested.
Overview
Fixes an infinite hydration retry loop when an early
adoptBindingshost sits next to stale server DOM that mismatch recovery removes duringhydrateRoot.Hydration now records parents touched by mismatch recovery in a new
repairedServerParentsWeakSet (HydrationCapability.save). Early host binding leases treat a recorded neighbor that was detached as still valid when that neighbor was removed as part of recovery under a repaired parent—matching the no–early-binding path: drop stale nodes, emit one recoverable error, keep the adopted host, and complete handoff. Any other neighbor change (including manual removal before/during lease) still refuses the lease (error #77).Adds behavior-root coverage for nested/root placement, matching vs stale vs externally removed neighbors (dev/prod), plus a case where an earlier hydration repair must not excuse a later external DOM change.
Reviewed by Cursor Bugbot for commit 08b1fea. Bugbot is set up for automated code reviews on this repo. Configure here.