Repository navigation
Description
Summary
A suspended hydration attempt can let an external neighbor removal be treated as its own mismatch repair. When the attempt resumes, hydration accepts the handoff and unsubscribes an early binding even though the host no longer has its recorded neighboring node.
Reproduction
Tested against source commit 71d40705014cad64028d2be5218fb53ab38d457b, with Node 26.2.0 and Vitest 4.1.10 in jsdom. The test uses the repository's compiler fixture helper and creates one mismatched sibling. It suspends the client, removes the restored sibling externally, then resolves the suspension and publishes an early-source update.
Save this file as packages/octane/tests/host-suspended-external-removal.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 { useLayoutEffect } from "octane";
import { unbound } from "octane/behavior";
export function Button(props) @{
"use dom bindings";
<button data-state={props.label}>{unbound(props.children)}</button>
}
export const gate = { thrown: undefined };
function readGate() { if (gate.thrown !== undefined) throw gate.thrown; return "done"; }
function Gate() @{ <i>{readGate()}</i> }
export function Parent(props) @{
useLayoutEffect(() => { props.onCommit(); });
<section><Button label={props.label}><span>Hello</span></Button><Gate /></section>
}
`;
describe("nested early host handoff during hydration", () => {
let root: ReturnType<typeof hydrateRoot> | undefined;
let binding: DomBindings.BindingHandle | undefined;
let container: HTMLElement;
afterEach(() => {
binding?.dispose();
root?.unmount();
container?.remove();
});
it("preserves a claimed early owner after external neighbor removal", async () => {
const external = process.env.OCTANE_EXTERNAL_DELETE === "1";
const extra = true;
const id = "/src/generic-handoff.tsrx";
const dev = process.env.OCTANE_TEST_COMPILE_MODE !== "prod";
const compileOptions = {dev, hmr: false, strong: process.env.OCTANE_GENERIC_STRONG === "1"};
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 "./generic-handoff.tsrx";
export function attach(root, source) { return adoptBindings(root, Button, source); }
`, {id:"/src/activate.tsrx", mode:"client", compileOptions, runtimeModules:{
"octane/behavior": DomBindings,
"octane/dom-bindings": DomBindings,
"./generic-handoff.tsrx?octane-bindings=Button":descriptor,
}});
const committed = vi.fn();
const props = {label:"ready", onCommit: committed};
let snapshot = props;
const listeners = new Set<() => void>();
const cleanup = vi.fn();
const uncaught = vi.fn();
container = document.createElement("div");
document.body.append(container);
container.innerHTML = renderToString(server.Parent, props).html;
const button = container.querySelector("button")!;
const script = document.createElement("script");
script.type = "application/json";
script.textContent = "{}";
if (extra) button.after(script);
binding = activation.attach(button, {
getSnapshot: () => snapshot,
subscribe: (listener: () => void) => {
listeners.add(listener);
return () => { listeners.delete(listener); cleanup(); };
},
});
let release!: () => void;
const wait = new Promise<void>((resolve) => { release = resolve; });
client.gate.thrown = wait;
root = hydrateRoot(container, client.Parent, props, {bindingLeases: [binding!], onUncaughtError: uncaught});
await act(async () => {});
expect(script.isConnected).toBe(true);
expect(committed).not.toHaveBeenCalled();
if (external) script.remove();
const cleanupBeforeResume = cleanup.mock.calls.length;
client.gate.thrown = undefined;
let resumeError: unknown;
try {
await act(async () => { release(); await wait; });
} catch (error) {
resumeError = error;
}
snapshot = {...props, label: "late"};
for (const listener of listeners) listener();
console.info("OBSERVATION", {
external, cleanupBeforeResume, cleanupAfterResume: cleanup.mock.calls.length,
commitCount: committed.mock.calls.length, original: container.querySelector("button") === button,
buttonConnected: button.isConnected, valueAfterLatePublication: button.getAttribute("data-state"),
uncaught: uncaught.mock.calls.map(([error]) => String(error)), resumeError: String(resumeError ?? ""),
});
if (external) {
expect(cleanup).not.toHaveBeenCalled();
expect(committed).not.toHaveBeenCalled();
expect(container.querySelector("button")).toBe(button);
expect(button.getAttribute("data-state")).toBe("late");
} else {
expect(committed).toHaveBeenCalledTimes(1);
expect(container.querySelector("button")).toBe(button);
}
});
});Save this configuration as vitest.neighbor-repro.config.mjs at the repository root:
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 pkgRoot = resolve(import.meta.dirname, "packages/octane");
const pkg = JSON.parse(readFileSync(resolve(pkgRoot, "package.json"), "utf8"));
const alias = Object.entries(pkg.exports)
.map(([name, target]) => ({
find: name === "." ? "octane" : "octane" + name.slice(1),
replacement: resolve(pkgRoot, typeof target === "string" ? target : target.default),
}))
.sort((a, b) => b.find.length - a.find.length);
export default defineConfig({
test: {
projects: scopedSignalsProjects(octane)
.filter((p) => ["octane-signals", "octane-signals-prod", "octane-signals-strong"].includes(p.test?.name))
.map((p) => ({
...p,
resolve: { alias },
test: {
...p.test,
env: { ...p.test.env, OCTANE_GENERIC_STRONG: p.test.name === "octane-signals-strong" ? "1" : "0" },
include: ["packages/octane/tests/host-suspended-external-removal.test.ts"],
exclude: [],
testTimeout: 15000,
},
})),
},
});With the repository dependencies installed:
OCTANE_EXTERNAL_DELETE=0 pnpm exec vitest run --project octane-signals --config vitest.neighbor-repro.config.mjs packages/octane/tests/host-suspended-external-removal.test.ts --reporter=verbose
OCTANE_EXTERNAL_DELETE=1 pnpm exec vitest run --project octane-signals --config vitest.neighbor-repro.config.mjs packages/octane/tests/host-suspended-external-removal.test.ts --reporter=verboseThe first command is the unchanged-site control. Remove --project octane-signals to run development, production and Strong projects; the configuration enables the Strong compiler for its project.
Expected
When a claimed early host's recorded neighbor is removed by outside code, the handoff should refuse the changed site. The original subscription stays live and its next update reaches the button. This follows the lease fence stated in #1751, which permits removal by mismatch recovery but treats other neighbor changes as a different site.
Actual
On the pinned source, the unchanged-site control completes hydration and preserves the button. In the external-removal case, hydration unsubscribes the early source and commits; the subsequent source update leaves the original button at ready instead of late. The test fails on the subscription-cleanup assertion.
The same fixture on Octane 0.9.1 retains the early subscription and displays late after the external removal. That run's behavioral assertions passed, but Vitest reported an asynchronous unsupported-handoff exception after the test, so it was not a clean test-suite pass.
The relevant repair was introduced in #1751 for #1743. This report concerns a distinct ownership condition after a suspended attempt; it does not dispute the stale-sibling recovery itself.
Activity
fix(octane): refuse an early host whose neighbor was removed while hy…