Repository navigation
Description
A moved early-bound host can keep publishing after its pending boundary hydrates a replacement
A host bound with adoptBindings can move elsewhere inside the same root while its boundary is pending. When that boundary resumes, Octane rebuilds a new host at the original location, but the moved host’s early binding remains subscribed and continues to write. A matching unmoved control hands the early binding off and unsubscribes normally.
This is distinct from #1743: the reproduction below has matching server/client output and no extra server tail.
Environment: Octane 0.9.1 source at 3b6db2b380724a6c04982d5bafbdcefd4d62baf3, Node 26.2.0, Vitest 4.1.10, jsdom 30.0.1, @tsrx/core 0.4.0 and @tsrx/oxc 0.16.0. This is a source-checkout/jsdom test; it has not been checked against the published package or a browser. The repository’s scoped dependencies were used for the test; a full-workspace install was not verified.
Reproduction: Install the repository dependencies and add these two files at the paths shown. From the repository root, run:
./node_modules/.bin/vitest run --config vitest.moved-repro.config.mjs --project octane-signals --maxWorkers=1 --reporter=verbose packages/octane/tests/host-moved-inside-root-control.test.tsThe test server-renders two host components, installs early bindings, and suspends their client boundaries. When the first boundary resumes, its binding cleanup optionally moves the second host into an already rendered <aside>. Then the second boundary resumes and the test publishes to its original binding source.
Expected: The renderer should not commit a replacement for a host while leaving the displaced host’s early binding active. It could refuse the takeover and retain the early owner, or safely retire that owner before committing a replacement; either outcome should preserve the externally moved DOM.
Actual: The unmoved case passes: the second binding’s cleanup runs once, and a later notification does not write through it. In the moved case the renderer reports a recoverable hydration mismatch and creates a replacement, but the cleanup is not called and the next source notification changes the moved original from ready to late-early-owner, while the replacement remains ready. No uncaught error is reported. The moved case fails at the cleanup assertion.
vitest.moved-repro.config.mjs
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import { defineConfig } from "vitest/config";
import { octane } from "./packages/octane/src/compiler/vite.js";
import { scopedSignalsProjects } from "./scripts/scoped-signals-projects.mjs";
const root = resolve(import.meta.dirname, "packages/octane");
const pkg = JSON.parse(readFileSync(resolve(root, "package.json"), "utf8"));
const alias = Object.entries(pkg.exports).map(([name, target]) => ({
find: name === "." ? "octane" : "octane" + name.slice(1),
replacement: resolve(root, typeof target === "string" ? target : target.default),
})).sort((a, b) => b.find.length - a.find.length);
export default defineConfig({
test: {
projects: scopedSignalsProjects(octane)
.filter((project) => project.test?.name === "octane-signals")
.map((project) => ({
...project,
resolve: { alias },
test: { ...project.test, include: ["packages/octane/tests/host-moved-inside-root-control.test.ts"], exclude: [] },
})),
},
});packages/octane/tests/host-moved-inside-root-control.test.ts
import { afterEach, describe, expect, it, vi } from "vitest";
import { act, hydrateRoot } from "octane";
import { renderToString } from "octane/server";
import * as DomBindings from "../src/dom-bindings.js";
import * as DomBindingSignals from "../src/dom-binding-signals.js";
import { loadCompiledFixtureSource } from "./_server-fixture.js";
const source = `
import { unbound } from "octane/behavior";
export function Button(props) @{
"use dom bindings";
<button data-state={props.label}>{unbound(props.children)}</button>
}
export const gates = { a: undefined, b: undefined };
function readGate(key) { if (gates[key] !== undefined) throw gates[key]; return "done"; }
function Gate(props) @{ <i>{readGate(props.id)}</i> }
export function Parent(props) @{
<section><aside id="destination"></aside>
@try { <><Button label={props.label}><span>First</span></Button><Gate id="a" /></> } @pending { <p>waiting a</p> }
@try { <><Button label={props.label}><span>Second</span></Button><Gate id="b" /></> } @pending { <p>waiting b</p> }
</section>
}
`;
describe("early binding retirement after an in-root host move", () => {
let root: ReturnType<typeof hydrateRoot> | undefined;
let bindings: DomBindings.BindingHandle[] = [];
let container: HTMLElement;
afterEach(() => {
root?.unmount();
for (const binding of bindings) binding.dispose();
bindings = [];
container?.remove();
});
it.each([false, true])("retires the early binding after resume (moved: %s)", async (move) => {
const id = "/src/retirement.tsrx";
const compileOptions = { dev: true, hmr: false };
const modules = {
"octane/behavior": DomBindings,
"octane/dom-bindings": DomBindings,
"octane/dom-binding-signals": DomBindingSignals,
};
const server = loadCompiledFixtureSource(source, { id, mode: "server", compileOptions, runtimeModules: modules });
const client = loadCompiledFixtureSource(source, { id, mode: "client", compileOptions, runtimeModules: modules });
const descriptor = loadCompiledFixtureSource(source, { id: id + "?octane-bindings=Button", mode: "client", compileOptions, runtimeModules: modules });
const activation = loadCompiledFixtureSource(`
import { adoptBindings } from "octane/behavior";
import { Button } from "./retirement.tsrx";
export function attach(root, source) { return adoptBindings(root, Button, source); }
`, { id: "/src/activate.tsrx", mode: "client", compileOptions, runtimeModules: {
...modules,
"./retirement.tsrx?octane-bindings=Button": descriptor,
}});
const props = { label: "ready" };
let snapshot = props;
let publishSecond!: () => void;
const secondCleanup = vi.fn();
container = document.createElement("div");
document.body.append(container);
container.innerHTML = renderToString(server.Parent, props).html;
const buttons = [...container.querySelectorAll("button")];
const destination = container.querySelector("#destination")!;
const firstCleanup = vi.fn(() => { if (move) destination.append(buttons[1]); });
bindings = buttons.map((button, i) => activation.attach(button, {
getSnapshot: () => snapshot,
subscribe: (publish: () => void) => {
if (i === 1) publishSecond = publish;
return i === 0 ? firstCleanup : secondCleanup;
},
}));
let releaseA!: () => void;
let releaseB!: () => void;
const waitA = new Promise<void>((resolve) => { releaseA = resolve; });
const waitB = new Promise<void>((resolve) => { releaseB = resolve; });
client.gates.a = waitA;
client.gates.b = waitB;
const uncaught = vi.fn();
root = hydrateRoot(container, client.Parent, props, { bindingLeases: bindings, onUncaughtError: uncaught });
await act(async () => {});
client.gates.a = undefined;
await act(async () => { releaseA(); await waitA; });
expect(destination.contains(buttons[1])).toBe(move);
client.gates.b = undefined;
await act(async () => { releaseB(); await waitB; });
const replacement = [...container.querySelectorAll("button")].find((button) => button !== buttons[0] && button !== buttons[1]);
if (!move) expect(replacement).toBeUndefined();
snapshot = { label: "late-early-owner" };
await act(async () => { publishSecond(); });
console.info("RETIREMENT_RESULT", { move, cleanupCalls: secondCleanup.mock.calls.length, oldLabel: buttons[1].getAttribute("data-state"), replacementLabel: replacement?.getAttribute("data-state"), uncaught: uncaught.mock.calls.length });
// Once the renderer commits a replacement, the old binding must not also
// continue publishing. Refusal that retains the original is another safe outcome.
if (!move || replacement !== undefined) {
expect(secondCleanup).toHaveBeenCalledTimes(1);
expect(buttons[1].getAttribute("data-state")).toBe("ready");
}
});
});
Activity
domgan-oai commentedon Oct 5, 2026
I reproduced the same behavior in headless Chromium using the published [email protected] package. The unmoved control passes: the early binding is cleaned up once and no replacement appears. In the relocated case a replacement appears, cleanup has not run, and a subsequent source notification changes the original host to
late-early-ownerwhile the replacement remainsready; the cleanup assertion fails. The fixture useshmr: false.Environment: Node 26.2.0, Vite 8.1.5, Vitest and @vitest/browser-playwright 4.1.11, Playwright 1.62.1, Chromium 151.0.7922.34. The installed npm package has integrity
sha512-1uNL9W6PP5eRhLH9jnieFm9Tpez0X70bnW1gBgxNO+zMMqkUiERrTA0LtAt6tLZE7E03D4iOOi9w8BHVwoXd0Q==.To reproduce, put these files in an empty directory, run
npm installandnpx playwright install chromium, then run each case:The Vite middleware produces server markup with
octane/server; the test installs two early bindings, delays their boundaries, and moves the second host from the first binding's cleanup. The assertion permits refusal that retains the original, while requiring cleanup if a replacement commits.package.json
{ "name": "octane-binding-move-repro", "private": true, "type": "module", "dependencies": { "@tsrx/core": "0.4.0", "octane": "0.9.1" }, "devDependencies": { "@vitest/browser-playwright": "4.1.11", "playwright": "1.62.1", "typescript": "5.9.3", "vite": "8.1.5", "vitest": "4.1.11" } }fixture.tsrx
attach.tsrx
vite.config.mts
hydration.browser.test.ts
fix(octane): retire a moved early host binding when hydration replace…