Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[2.0 rc.17] A lone spread runs before the element's hydration key on the server, after it on the client

Chiusa
#4,240 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
1-2 giorni
Idoneità per principianti
58/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, typescript

Direzione di ricerca

Start by tracing how the compiler emits server output for a JSX element with a lone spread, then compare it with the client output described in the issue. Check the ssrElement hydration-key allocation and the existing spread compilation tests. Done when a lone spread runs after the server element's hydration key and the reported hydration mismatch is covered by a regression test.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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).

Lingua principale
TypeScript
Stelle
36.2k
Fork
1.1k
Merge medio
11h
PR unite (30g)
343

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di solidjs/solid

Tutte le issue di solidjs/solid

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.