Skip to content

innerHTML from a call expression consumes an extra hydration id — the next element is left unclaimed #3015

Closed

Description

@TylerRick

Describe the bug

On solid-js / @solidjs/web 2.0.0-rc.0, an element whose innerHTML value comes from a call expression consumes two hydration ids on the server but one on the client. Every keyed element created after it then claims the wrong node: the last one is left unclaimed, and Solid discards the server's DOM for it and rebuilds it.

const svg = (r: number) =>
	`<svg width="16" height="16" viewBox="0 0 16 16"><circle cx="8" cy="8" r="${r}" /></svg>`;

function Icon(props: { radius: number }) {
	return <div class="icon" innerHTML={svg(props.radius)} />;
}

export default function App() {
	const [checked, setChecked] = createSignal(false);
	return (
		<div class="wrap">
			<Icon radius={7} />
			<Icon radius={4} />
			<input
				id="toggle"
				type="checkbox"
				checked={checked()}
				onChange={(e) => setChecked(e.currentTarget.checked)}
			/>
			<pre id="after">after: {String(checked())}</pre>
		</div>
	);
}

Server markup — note the id gap, 0, 1, 3:

<div _hk="0" class="wrap">
	<div _hk="1" class="icon"><svg …r="7"…></svg></div>
	<div _hk="3" class="icon"><svg …r="4"…></svg></div>
	<input id="toggle" type="checkbox" />
	<pre id="after">after: false</pre>
</div>

Client console after hydrate():

Hydration completed with 1 unclaimed server-rendered node(s):
  <div _hk="3" class="icon"><svg width="16" height="16" viewBox="0 0 16 16"><circle cx="8" cy="8" r="4…

Control

Identical tree, with the same string written inline instead of returned by a call:

function Icon(props: { radius: number }) {
	return (
		<div
			class="icon"
			innerHTML={`<svg width="16" height="16" viewBox="0 0 16 16"><circle cx="8" cy="8" r="${props.radius}" /></svg>`}
		/>
	);
}

Server ids are 0, 1, 2 and hydration completes with no warning. Wrapping the call version's element in a constant <Show when> also hydrates cleanly.

Why it matters

In the reduced case above Solid recovers — it rebuilds the unclaimed node, and reactivity survives. In the app where this was found (an <Icon> component that builds its SVG through iconSvg(name), used across a login form), the mis-claim landed on a sibling instead: a later template claimed the password input's node and the field was removed from the DOM, with no error beyond the same unclaimed-nodes warning. That is the failure mode to worry about — it is silent and it deletes user-visible markup.

Reproduction

Standalone project: vite 8.2.1 + vite-plugin-solid 3.0.0-next.27, solid-js/@solidjs/web 2.0.0-rc.0, renderToStream on the server + hydrate on the client. No other packages. src/App.tsx is the snippet above, src/AppFixed.tsx the control (served at /?fix); the rest is boilerplate:

package.json
{
	"name": "solid2-innerhtml-hydration-key-repro",
	"private": true,
	"type": "module",
	"scripts": { "dev": "node server.mjs" },
	"dependencies": {
		"@solidjs/web": "2.0.0-rc.0",
		"solid-js": "2.0.0-rc.0"
	},
	"devDependencies": {
		"vite": "8.2.1",
		"vite-plugin-solid": "3.0.0-next.27"
	}
}
vite.config.mjs
import { defineConfig } from 'vite';
import solid from 'vite-plugin-solid';

export default defineConfig({
	plugins: [solid({ ssr: true })],
	server: { port: 5594, strictPort: true },
});
server.mjs
import http from 'node:http';
import { createServer as createViteServer } from 'vite';

const vite = await createViteServer({
	configFile: './vite.config.mjs',
	server: { middlewareMode: true },
	appType: 'custom',
});

const server = http.createServer((req, res) => {
	vite.middlewares(req, res, async () => {
		const { render } = await vite.ssrLoadModule('/src/entry-server.tsx');
		res.setHeader('content-type', 'text/html');
		res.end(await render(req.url.includes('fix')));
	});
});
server.listen(5594, () => console.log('repro on http://localhost:5594'));
src/entry-server.tsx
import { generateHydrationScript, renderToStream } from '@solidjs/web';
import App from './App';
import AppFixed from './AppFixed';

export async function render(fixed: boolean): Promise<string> {
	const Root = fixed ? AppFixed : App;
	const stream = renderToStream(() => <Root />);
	const chunks: string[] = [];
	const decoder = new TextDecoder();
	await stream.pipeTo(
		new WritableStream({
			write(chunk) {
				chunks.push(typeof chunk === 'string' ? chunk : decoder.decode(chunk));
			},
		}),
	);
	return `<!doctype html>
<html>
<head><meta charset="utf-8" />${generateHydrationScript()}</head>
<body>
<div id="root">${chunks.join('')}</div>
<script type="module" src="/src/entry-client.tsx"></script>
</body>
</html>`;
}
src/entry-client.tsx
import { hydrate } from '@solidjs/web';
import App from './App';
import AppFixed from './AppFixed';

const Root = location.search.includes('fix') ? AppFixed : App;
hydrate(() => <Root />, document.getElementById('root'));

Expected behavior

An innerHTML element consumes the same number of hydration ids on the server as on the client, regardless of whether its value is written inline or returned by a function.

Platform

  • solid-js / @solidjs/web: 2.0.0-rc.0
  • vite 8.2.1, vite-plugin-solid 3.0.0-next.27
  • Chromium 141, Linux

Activity

  1. Fnine59 commented on Aug 18, 2026

    @Fnine59

    Additional diagnosis: this is blocked on the upstream compiler rather than needing a Solid runtime change.

    I reproduced the mismatch on Solid next at 366da098 with both the native and Babel compiler backends. A focused SSR regression fails consistently with expected consecutive innerHTML hydration ids 0,1,2; received 0,1,3.

    For innerHTML={svg(...)}, SSR lowers the value through scope(() => svg(...)), while DOM lowering uses the ordinary effect plus setProperty(..., "innerHTML", ...) path. The SSR scope reserves an extra hydration/owner slot only on the server; inline template and member-expression controls do not get that scope.

    The allocation originates in dom-expressions next at df133ea9, in both compiler paths:

    • Babel: packages/babel-plugin-jsx/src/ssr/element.ts redirects innerHTML to an opaque synthesized child but still applies the generic hydratable-child allocation test and scope() to dynamic calls.
    • Native: packages/compiler/src/ssr/transform.rs mirrors that behavior by applying scope_expression to the do_not_escape pseudo-child.

    A correct fix therefore needs both dom-expressions compiler paths to make opaque innerHTML pseudo-children bypass real child-hole ID scoping, followed by a compiler release and dependency bump here. I did not open a Solid-side workaround: after DOM lowering the call and inline forms are indistinguishable property effects, and changing ssrScope globally would affect genuine deferred dynamic children.

  2. ryansolid commented on Aug 18, 2026

    @ryansolid
    Member

    Fixed in ryansolid/dom-expressions@b02414c3 (both compilers), with an end-to-end parity scenario in 943c029.

    Root cause: both SSR generates redirect innerHTML (and textContent) into the element's child pipeline. There, a call-shaped value matched the deferred-hole predicate ("could return components") and was wrapped in _$scope(...), which reserves a hydration child id on the server. But the client applies these props as plain setProperty effects with no owner — it never allocates that id — so every hydratable sibling after the hole shifted by one (_hk 0, 1, 3 vs. the client's 0, 1, 2) and went unclaimed: frozen, detached DOM with zero errors. An inline template literal dodged it only because a template literal fails the "could return components" shape check.

    The fix teaches both compilers that these redirects are opaque content that can never allocate ids, so the hole compiles to a plain thunk and ids stay consecutive. The children attribute redirect keeps its scope — it's a real insert on the client and scopes on both sides. Lands in the next published dom-expressions snapshot.

  3. TylerRick commented on Aug 18, 2026

    @TylerRick
    Author

    [Comment deleted]

    Update: Man, you're quick! I had tried to verify against the next branch at 383d2a5f and used dom-expressions at 86a5100d (4 commits behind b02414c3), which is before your fix. So, my comment was a false alarm and I confirmed that this is fixed now.

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