Repository navigation
Description
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
Fnine59 commentedon Aug 18, 2026
Additional diagnosis: this is blocked on the upstream compiler rather than needing a Solid runtime change.
I reproduced the mismatch on Solid
nextat366da098with both the native and Babel compiler backends. A focused SSR regression fails consistently withexpected consecutive innerHTML hydration ids 0,1,2; received 0,1,3.For
innerHTML={svg(...)}, SSR lowers the value throughscope(() => svg(...)), while DOM lowering uses the ordinary effect plussetProperty(..., "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-expressionsnextatdf133ea9, in both compiler paths:packages/babel-plugin-jsx/src/ssr/element.tsredirectsinnerHTMLto an opaque synthesized child but still applies the generic hydratable-child allocation test andscope()to dynamic calls.packages/compiler/src/ssr/transform.rsmirrors that behavior by applyingscope_expressionto thedo_not_escapepseudo-child.A correct fix therefore needs both
dom-expressionscompiler paths to make opaqueinnerHTMLpseudo-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 changingssrScopeglobally would affect genuine deferred dynamic children.fix(compilers): innerHTML/textContent holes never take the _$scope id…
test: parity scenario for call-shaped innerHTML id drift (#3015)
ryansolid commentedon Aug 18, 2026
Fixed in ryansolid/dom-expressions@b02414c3 (both compilers), with an end-to-end parity scenario in 943c029.
Root cause: both SSR generates redirect
innerHTML(andtextContent) 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 plainsetPropertyeffects with no owner — it never allocates that id — so every hydratable sibling after the hole shifted by one (_hk0, 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
childrenattribute 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.TylerRick commentedon Aug 18, 2026
[Comment deleted]
Update: Man, you're quick! I had tried to verify against the
nextbranch at383d2a5fand used dom-expressions at86a5100d(4 commits behind b02414c3), which is before your fix. So, my comment was a false alarm and I confirmed that this is fixed now.unlock @dom-expressions/compiler from the exact 0.50.0-next.40 pin to…
chore: bump dom-expressions to 0.50.0-next.43 and vite-plugin to 3.0.…
fix(compilers): textarea value fold must not reserve a hydration id (#…
chore(deps): update dependency @solidjs/vite-plugin to v3.0.0 (#92)
Update dependency @solidjs/vite-plugin to v3.0.0 (#52)