Skip to content

Native blur runs against a disposed component during removal #1472

Closed

Description

@petetheheat-oai

Confirmed on unmodified Octane 0.6.2 source at 867ab3a40e5b8af863d5c566eadee5ad97ca3091, Chromium 149.0.7827.55, Node 26.2.0. Both development and production browser bundles reproduce it.

A compiled form owns a local signal and updates it in onBlur. If its input is focused, root.unmount() disposes the signal and then removes the DOM. Chromium dispatches focusout synchronously during removal. Octane's still-active delegation calls the form handler and reports ScopeDisposedError (production error 151).

import { useSignal$ } from 'octane/signals/client';
export function App() @{
 const count$ = useSignal$(0);
 <form onBlur={() => count$.set(1)}>
  <input /><output>{count$.get() as number}</output>
 </form>
}

Mount App with createRoot, focus its input, then call root.unmount. An ordinary input.blur before unmount succeeds.

Expected: teardown does not start a new handler invocation on a retired renderer scope. Normal blur, handlers already captured by an active dispatch, and handlers owned by other live roots should keep working.

Root cause: root.unmount calls unmountBlock(rootBlock, false) before clearRootContainer, and deregisters delegation afterward. The delegated snapshot stores signal authority but does not check renderer lifetime. The same defect reproduces when removing the rendered child, removing a portal, or disposing a nested root.

A runtime source patch records the renderer scope of actual event hosts alongside their signal authority, using the existing staged and rollback journal path. New phase snapshots omit retired renderer scopes. Existing captured handlers and signal retirement remain unchanged. Republish outside rendering clears a prior renderer association.

Verification: the independent browser regression below passes its two normal-blur controls and fails all 12 removal cases before the patch; all 14 pass with the patch. Four existing event-authority, bundle-capture and rollback suites pass 103 tests after the patch, including already queued handlers retaining their original retired signal authority. The complete matched package build passes, and only runtime.js plus cjs/runtime.cjs change in its 459-file distribution. The browser fixture does not use services or application data.

Dependency qualification: the before run uses the pinned public Octane 0.6.2 runtime/compiler source at 867ab3a40e5b8af863d5c566eadee5ad97ca3091, paired with TSRX core 0.4.0 / runtime 0.2.4 source at d3dc6bab4e4fc63f93173a662345b7d3d6c91a00 and the public directive-gap fix. Package version metadata was normalized for the build; the runtime source was unmodified for the before run. This does not claim pristine npm tarballs for all dependencies. The fixture contains no directives or scoped styles. Public main's corresponding disposal and dispatch functions were also inspected and still had this order, but main was not executed.

The repository setup commands are below. The measured runs used the pinned source build and dependency qualification above; a fresh full-workspace install with these commands was not independently run.

git clone https://github.com/octanejs/octane.git octane-blur-repro
cd octane-blur-repro
git checkout 867ab3a40e5b8af863d5c566eadee5ad97ca3091
pnpm install --frozen-lockfile
pnpm exec playwright install chromium

Save the test below as packages/octane/tests/browser/retired-event-host/retired-event-host.test.ts. Save this focused configuration as vitest.retired-event-host.config.mjs:

import { defineConfig } from 'vitest/config';
export default defineConfig({ test: {
 environment: 'node',
 include: ['packages/octane/tests/browser/retired-event-host/retired-event-host.test.ts'],
 testTimeout: 30000, hookTimeout: 30000, maxWorkers: 1, fileParallelism: false,
} });
node node_modules/vitest/vitest.mjs run --config vitest.retired-event-host.config.mjs

An existing Chrome executable can be selected with OCTANE_BROWSER_EXECUTABLE_PATH.

Complete independent browser regression
import { createRequire } from 'node:module';
import { fileURLToPath } from 'node:url';
import { build } from 'esbuild';
import type { Browser } from 'playwright';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { launchBrowser } from '../../../../../test-utils/playwright-browser.js';
import { compile } from '../../../src/compiler/index.js';

const packageRoot = fileURLToPath(new URL('../../..', import.meta.url));
const packageRequire = createRequire(new URL('../../../package.json', import.meta.url));
const fixture = `
import { useSignal$ } from 'octane/signals/client';
export function App({ observe }) @{
 const count$ = useSignal$(0);
 <form onBlur={() => { observe('blur'); count$.set(1); observe('write'); }}>
  <input aria-label="Synthetic input" /><output>{count$.get() as number}</output>
 </form>
}`;
let browser: Browser;
const bundles = new Map<boolean, string>();
beforeAll(async () => {
	for (const dev of [false, true]) {
		const compiled = compile(fixture, '/retired-event-host.tsrx', {
			mode: 'client',
			dev,
			hmr: false,
			strong: true,
		});
		expect(compiled.diagnostics).toEqual([]);
		const output = await build({
			stdin: {
				contents:
					compiled.code +
					`\nexport { createRoot, createElement, createPortal, flushSync, setEventHandler } from 'octane';`,
				resolveDir: packageRoot,
				sourcefile: 'retired-event-host.js',
			},
			bundle: true,
			write: false,
			format: 'iife',
			platform: 'browser',
			globalName: 'OctaneRetiredEventHost',
			define: {
				'process.env.NODE_ENV': JSON.stringify(dev ? 'development' : 'production'),
				__OCTANE_PROFILE_ENABLED__: 'false',
			},
			plugins: [
				{
					name: 'octane-source',
					setup(plugin) {
						plugin.onResolve({ filter: /^octane(?:\/|$)/ }, ({ path }) => ({
							path: packageRequire.resolve(path),
						}));
					},
				},
			],
		});
		bundles.set(dev, output.outputFiles[0].text);
	}
	browser = await launchBrowser({
		headless: true,
		...(process.env.OCTANE_BROWSER_EXECUTABLE_PATH
			? { executablePath: process.env.OCTANE_BROWSER_EXECUTABLE_PATH }
			: {}),
	});
});
afterAll(async () => {
	await browser?.close();
});

describe.sequential('new native events on retired renderer hosts', () => {
	for (const dev of [false, true]) {
		for (const scenario of [
			'ordinary-blur',
			'root-unmount',
			'remove-child',
			'portal-unmount',
			'nested-root-unmount',
			'other-live-root',
			'rebound-host',
		] as const) {
			it(`${scenario} (dev=${dev})`, async () => {
				const page = await browser.newPage();
				const failures: string[] = [];
				page.on('pageerror', (error) => failures.push(error.message));
				page.on('console', (message) => {
					if (message.type() === 'warning' || message.type() === 'error')
						failures.push(message.text());
				});
				try {
					await page.setContent(
						'<!doctype html><body><div id="outer"></div><div id="root"></div><div id="portal"></div><div id="other"></div><button id="outside">Outside</button></body>',
					);
					await page.addScriptTag({ content: bundles.get(dev)! });
					const result = await page.evaluate((scenario) => {
						const { createRoot, createElement, createPortal, flushSync, setEventHandler, App } = (
							window as any
						).OctaneRetiredEventHost;
						const seen: string[] = [];
						const observe = (value: string) => seen.push(value);
						let host = document.getElementById('root')!;
						let outerRoot: any;
						let otherRoot: any;
						if (scenario === 'nested-root-unmount') {
							outerRoot = createRoot(document.getElementById('outer'));
							flushSync(() =>
								outerRoot.render(
									createElement(
										'section',
										{ onBlur: () => seen.push('outer-blur') },
										createElement('div', { id: 'nested' }),
									),
								),
							);
							host = document.getElementById('nested')!;
						}
						const root = createRoot(host);
						const portal = document.getElementById('portal')!;
						flushSync(() =>
							root.render(
								scenario === 'portal-unmount'
									? createPortal(createElement(App, { observe }), portal)
									: createElement(App, { observe }),
							),
						);
						if (scenario === 'other-live-root' || scenario === 'rebound-host') {
							otherRoot = createRoot(document.getElementById('other'));
							flushSync(() =>
								otherRoot.render(
									createElement(App, { observe: (value: string) => seen.push('other-' + value) }),
								),
							);
						}
						const input = (scenario === 'portal-unmount' ? portal : host).querySelector('input')!;
						const form = input.closest('form')!;
						input.focus();
						const focused = document.activeElement === input;
						if (scenario === 'ordinary-blur') document.getElementById('outside')!.focus();
						else if (scenario === 'remove-child') flushSync(() => root.render(null));
						else root.unmount();
						if (scenario === 'other-live-root') {
							(document.querySelector('#other input') as HTMLInputElement).focus();
							document.getElementById('outside')!.focus();
						}
						if (scenario === 'rebound-host') {
							// Republish this retained native host outside rendering with new authority.
							setEventHandler(form, '$$focusout', () => seen.push('rebound-blur'));
							document.getElementById('other')!.append(form);
							input.focus();
							document.getElementById('outside')!.focus();
						}
						const observed = [...seen];
						root.unmount();
						otherRoot?.unmount();
						outerRoot?.unmount();
						return { focused, observed };
					}, scenario);
					expect(result.focused).toBe(true);
					expect(failures).toEqual([]);
					const expected =
						scenario === 'ordinary-blur'
							? ['blur', 'write']
							: scenario === 'nested-root-unmount'
								? ['outer-blur']
								: scenario === 'other-live-root'
									? ['other-blur', 'other-write']
									: scenario === 'rebound-host'
										? ['rebound-blur']
										: [];
					expect(result.observed).toEqual(expected);
				} finally {
					await page.close();
				}
			});
		}
	}
});

Agent-authored report and reproduction.

Activity

  1. added a commit that references this issue on Oct 2, 2026
    15c7b97
  2. added a commit that references this issue on Oct 4, 2026
    d5030cf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions