Repository navigation
fix(octane): retire a moved early host binding when hydration replaces it - #1748
Merged
Merged
Conversation
…s it A host leased through adoptBindings can be moved elsewhere inside the root while its boundary is pending. On resume, hydration no longer finds the host at the cursor, reports a recoverable mismatch, and renders its own host at the original site. The early lease was never matched, and commit-time retirement only checked container containment, so the moved host kept its subscription and later notifications wrote to it. The host lease now reports whether the renderer reached its original site (after the same authored neighbour) without finding it there. When a host-presentation component hydrates without a positional lease, it looks for such a displaced lease and retires it when the replacement's capture commits. A discarded or re-suspended attempt leaves the early owner live, and the moved DOM is never touched. Fixes #1745 Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
October 5, 2026 07:33
Contributor
Benchmark report
Compares js-framework: 1k/10k row operationsAll 20 timed operations (20 without a verdict)
All 64 work counters are unchanged. Application bundle size (bytes)
50 other measured values are unchanged. Public-import reachability bundles (bytes)No changes across 105 measured values. |
…OM check Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merged
7 tasks done
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
Fixes #1745.
A host bound with
adoptBindingscan be moved elsewhere inside the same root while its boundary is pending. On resume, hydration no longer finds the host at its cursor. It reports a recoverable mismatch and renders its own host at the original site. Before this change, the early lease was never matched, and commit-time retirement (retireDetachedBindingLeases) only retired leases whose host had left the container. The moved host therefore stayed subscribed, and later source notifications kept writing to it.The fix takes the issue's "retire before the replacement commits" option:
dom-bindings.ts/dom-binding-handoff.ts: a scalar host lease gains an optionaldisplaced(parent, node)check. It reports whether the renderer reached the host's server site (directly after the same authored neighbour, skipping renderer sidecars) and found another node or the end of the parent there. Nested component hosts are framed by their own block markers, so that neighbour identifies one instance.runtime.ts: when a host-presentation component hydrates and no lease matches positionally,beginPresentationHydrationlooks for a displaced lease with the same id. It registers that lease's retirement on the attempt's capture. Committing the replacement retires the early owner (cleanup runs, listeners and subscriptions stop), just as an accepted handoff would. A discarded or re-suspended attempt leaves the early owner live. The moved DOM is never touched.The unmoved control is unchanged: the binding still hands off in place. An invalid host that is still at the cursor still refuses takeover as before.
docs/deferred-hydration.mddocuments the new contract.Validation
pnpm format:check(scopedpnpm format:files:checkon every changed file passed)pnpm typecheck(scopedpnpm typecheck:fileson the changed source and test files passed)pnpm test(not run locally; left to CI)targeted tests:
vitest run --project octane packages/octane/tests/binding-handoff-displaced-host.test.ts, 10/10 passing in dev and prod compiles:<aside>;<Hydrate>boundary that a later render activates;Each moved case asserts that the cleanup ran once, a later notification no longer writes to the moved element, the moved element stays where it was moved, and a later root render updates only the renderer's host.
Pre-fix failure: with the runtime call disabled, all 8 moved cases fail (cleanup never runs, the moved host takes the late notification) and both controls pass. Removing the discarded-attempt guard fails only the re-suspend case in both modes.
Risk / follow-ups
bindingLeasesand a host-presentation component hydrates without a positional lease. It is a cold loop over that root's leases. No bundle-size app includesbeginPresentationHydration; the early scalar adopter grows by one small closure.beginPresentationHydration. Whichever lands second rebases.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 deferred hydration and early-binding retirement in edge cases where DOM moves during pending boundaries; incorrect matching could retire the wrong lease or leave stale writers.
Overview
Fixes stale early binding subscriptions when a scalar host is moved inside the root while its hydration boundary is still pending. On resume, hydration treats the host as missing at the original site, reports a recoverable mismatch, and renders a replacement at that site—but the displaced host’s lease could stay active, so later source notifications kept updating the moved DOM.
Scalar host leases now expose an optional
displaced(parent, node)check (server site identified via the same authored sibling, skipping renderer sidecars). When host presentation hydration finds no positional lease,supersedeDisplacedHostlooks for a displaced lease with the same id and schedulesretire()on commit of the replacement—matching accepted handoff cleanup without touching the moved element. Discarded or re-suspended attempts leave the early owner live.Deferred hydration docs describe this contract. New integration tests cover moved hosts (including re-suspend, dormant
<Hydrate>activation, and an external clone at the site). Staged-DOM checks whitelistparentNodereads in the new runtime path.Reviewed by Cursor Bugbot for commit d05043a. Bugbot is set up for automated code reviews on this repo. Configure here.