Repository navigation
Description
Describe the bug
Take an element whose only attribute is a spread: <label {...props()} />. The server compiles it to ssrElement(tag, props(), children, true), so props() is an argument and runs before ssrElement allocates the element's hydration key. The client compiles the same element to getNextElement(tmpl) and then spread(el, () => props()), so it claims the key first and runs props() afterwards.
If props() creates an owner (a memo, for example), the server gives that owner the id the element should get. The element's key then shifts by one, on the server only. The client misses the key, creates a detached element, and leaves the server node unclaimed and inert.
When the element has any other attribute, the server wraps the spread in a thunk (ssrElement(tag, [{...}, () => props()], ...)), runs it after the key, and the two sides agree.
Compiled output (@solidjs/vite-plugin 3.0.0-next.51, { ssr: true }):
// server: <label {...composeProps(row, () => ({ class: "x" }))} />
(row) => ssrElement("label", composeProps(row, () => ({ class: "x" })), undefined, true)
// client
var _el$ = _$getNextElement(_tmpl$);
_$spread(_el$, () => composeProps(row, () => ({ class: "x" })), false, undefined, "label")ssrElement takes the key inside the call (const hk = needsId ? ssrHydrationKey() : ""), after its arguments have been evaluated.
Your Example Website or App
Minimal repro below (no libraries).
Steps to Reproduce the Bug or Issue
// app.tsx: server-render with renderToString + generateHydrationScript, then hydrate(() => <App />, root)
import { createMemo, Show } from "solid-js";
// Creates an owner (a memo) while computing the spread.
const withMemo = () => {
const title = createMemo(() => "spread");
return { get title() { return title(); } };
};
export function App() {
return (
<main>
<Show when={true}>
<label {...withMemo()}>lone spread</label>
</Show>
<Show when={true}>
<label data-x="" {...withMemo()}>spread plus attribute</label>
</Show>
</main>
);
}Console on hydrate (dev):
Hydration key miss for "30": no server-rendered element carries this key (template: <label>lone spread). A detached element was created instead; ...
Hydration completed with 1 unclaimed server-rendered node(s):
<label _hk="31" title="spread">lone spread</label>
The second label (spread plus an attribute) hydrates.
Expected behavior
A lone spread is evaluated after the element's hydration key on the server, as it is on the client and as a spread next to other attributes already is. For example, emit ssrElement(tag, () => props(), ...), or take the key before evaluating the props.
Platform
- solid-js / @solidjs/web 2.0.0-rc.17
- @solidjs/vite-plugin 3.0.0-next.51 (@solidjs/compiler, @solidjs/babel-plugin 2.0.0-rc.17)
- Chromium (Playwright), Node 26
Additional context
We hit this in a component library, where a styled Switch renders <label {...composeProps(row, () => attrs)} /> and each accessor source becomes a memo. We worked around it by making those memos transparent: true. Related but different: #4081 (ref dropped on a spread element).
Activity