Repository navigation
Description
Unchanged trusted HTML replaces child nodes on the first post-hydration render
On Octane public source 0.4.2, commit 27abffc, a new trustHTML() wrapper with unchanged __html content causes the runtime to rewrite the host's children after hydration. Initial hydration preserves the server child, but an ordinary subsequent render replaces it with an identical new node.
This can interrupt a pointer gesture if activation triggers that render between pointerdown and pointerup: the pressed descendant no longer exists. The node replacement itself is independently reproduced by the existing framework fixture below; no application or network services are involved.
The existing packages/octane/tests/_fixtures/trusted-html.tsx already returns a fresh trusted wrapper on each invocation:
import { trustHTML } from 'octane';
export function TrustedMarkup(props: { html: string | null }) {
return <section dangerouslySetInnerHTML={props.html === null ? undefined : trustHTML(props.html)} />;
}Extend the existing renders, hydrates, updates, and clears HTML case in packages/octane/tests/trusted-html.test.ts, immediately after its initial hydration identity assertion:
const content = container.querySelector('b');
// Initial hydrateRoot preserves content, as the existing test verifies.
flushSync(() => root.render(client.TrustedMarkup, { ...props }));
expect(container.querySelector('b')).toBe(content);Expected: unchanged trusted content retains the same child node. Actual: the assertion fails in both development and production compilation, although the old and new nodes serialize identically. The unmodified public runtime control reports one existing case passed and both extended dev/prod cases failed.
Verified with Node 26.2.0, Vitest 4.1.11, jsdom 30.0.1, the pinned public source, and the framework's real server/client fixture compiler. The exact minimal config below independently reproduces the failure against the unmodified public runtime. Verification used an isolated dependency environment; a normal full upstream workspace install is not claimed.
Reproduction steps for the public repository (the full-workspace install step is unrun here):
git clone https://github.com/octanejs/octane.git
cd octane
git checkout 27abffc262ed4a1babc3306c999db0a03b5a42ee
pnpm install --frozen-lockfile --ignore-scriptsApply the two identity-check lines above to the existing test. Save this as vitest.trusted-html-repro.config.mjs in 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';
const packageRoot = resolve(import.meta.dirname, 'packages/octane');
const pkg = JSON.parse(readFileSync(resolve(packageRoot, 'package.json'), 'utf8'));
const alias = Object.entries(pkg.exports).map(([name, target]) => ({
find: name === '.' ? 'octane' : 'octane' + name.slice(1),
replacement: resolve(packageRoot, typeof target === 'string' ? target : target.default),
})).sort((a,b) => b.find.length - a.find.length);
export default defineConfig({
resolve: { alias },
plugins: [octane({ hmr: false })],
test: {
environment: 'jsdom',
setupFiles: ['packages/octane/tests/_per-test-setup.ts'],
include: ['packages/octane/tests/trusted-html.test.ts'],
},
});Run:
pnpm exec vitest run --config vitest.trusted-html-repro.config.mjs --maxWorkers=1 --no-file-parallelismThe independently verified isolated execution used the same public files and config, with node node_modules/vitest/vitest.mjs run --config vitest.trusted-html-repro.config.mjs --maxWorkers=1 --no-file-parallelism. Its complete original report records 1 passed / 2 failed existing cases.
The cause is setHTML() in packages/octane/src/runtime.ts. It compares normalized content during hydration, but afterward it unconditionally stages or assigns innerHTML when a fresh wrapper reaches the validated setter. The aggregate source cache compares wrapper identity and does not cover every direct/html-only compiler path.
A small source fix caches the last accepted HTML scalar in setHTML(), records successful matching hydration adoption, and skips identical later writes before DOM staging. The cache must be journaled with root transactions, cleared when raw HTML ownership ends, and left unset for suppressed hydration mismatches. Keep the existing malformed-value, void-host and child-conflict validation before this optimization.
The extended existing trusted HTML case passes with that fix. Its coverage also checks unchanged post-update content, repeated client-only renders, clear and restore. Existing ownership transition and suspended-render rollback cases can verify empty HTML after ordinary children and cache restoration after abandoned writes.
—Codex
Activity