[2.0.4] SSR hydration: server/client key-sequence drift leaves interactive elements permanently dead after hydration

Aperta
#5,226 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@leo7martins ci sta già lavorando.

Dal 27/11/2026.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
javascript, typescript, vite
Ambito
frontend, testing

Direzione di ricerca

Start by reproducing the issue with the linked solid-hydration-repro app using pnpm install && pnpm dev, then compare server and client hydration key sequences around onSettled, <Show>, and scope slots. The report identifies these server/client asymmetries but does not name the Solid source files or tests to change. Done means the client claims the server-rendered nodes and the button works after hydration in both dev and production.

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

Descrizione

Describe the bug

In SSR + hydration mode, interactive elements can be left permanently dead
after hydration: they render in the server HTML, but never receive event
handlers or reactive bindings — in dev and, silently, in a prerendered
production build (zero console output there; the dev-only warnings don't
fire). Clicking simply does nothing, on every load.

Concretely (from the app where this was found): a navigation-rail menu
button renders fine in the served HTML but is completely unresponsive after
hydration — in both vite dev SSR and the prerendered production build.
The client created a detached clone of the button's subtree with all
handlers, while the server-rendered copy stays in the document
handler-less.

The cause is hydration-id drift: the server build consumes hydration ids in
places where the client build never does, so the server's id sequence runs
ahead of the client's. Once the drift exceeds what the client's later render
passes can absorb, hydration claiming fails for the whole subtree — with the
symptoms above. Three server/client asymmetries in solid-js 2.0.4 consume
server-only hydration ids:

  1. onSettled — the server build is a reservation-only stub:

    function onSettled(callback) {
      const o = getOwner();
      if (o?.id != null) getNextChildId(o); // consumes an id, callback never runs
    }
    

    The client runs the callback in a tracked effect and consumes nothing.

  2. <Show> — the server build reserves a child id unconditionally for
    non-keyed Show (if (o?.id != null && !props.keyed) getNextChildId(o););
    the client Show allocates nothing.

  3. Scope slots — ssrScope / _scopeSlot / materializeId exist only in
    the server build; {props.children} / JSX-prop slots consume hidden ids
    server-side with no client counterpart.

These stack inside real component trees. A component chain rendered
through a JSX-prop <Show> boundary — custom-element wrappers, a tooltip
(with its focus-signal primitive), a dynamic() native button, more
<Show>s (icon/label/variant) and prop-slot renders — drifts the server
id sequence by a dozen+ ids for the subtree. Once the drift exceeds what
the client's later render passes happen to absorb, claiming fails
permanently for that subtree.

Your Example Website or App

https://github.com/mprovok/solid-hydration-repro

Steps to Reproduce the Bug or Issue
  1. Clone the linked repo and cd into it
  2. pnpm install && pnpm dev
  3. Open the page and watch the dev-server console: on every load,
    Hydration key miss warnings appear for the whole menu-button subtree
    (client looks up keys like 19h0; the server emitted 19e0 — visible
    via curl -s http://localhost:5173/ | grep -o '_hk=19e0'), ending
    with Hydration completed with 5 unclaimed server-rendered node(s)
    listing the chain
  4. You'll see a large vertical bar (the "navigation rail") on the left side of the screen and a smaller bar above it. Inside the small bar is a "button" (the rail's menu button) with a slightly darker blue background color. Click that button — nothing happens. The visible server
    sm-button has no delegated click handler
    (typeof document.querySelector('sm-navigation-rail sm-button')._$$click === "undefined"); the reactive graph bound to a detached clone
  5. pnpm build && pnpm preview — the dead button reproduces in
    production
    , silently: zero console output (all checks are dev-only),
    same unclaimed server nodes, same dead click — this is the silent
    production failure described at the top
Expected behavior

The client should claim the server-rendered nodes (matching hydration keys),
with no detached clones and no key misses. Interactive elements should stay
interactive after hydration, identically in dev and production.

If you enable the commented code in src/App.tsx so that onHydrationEnd is called, then after running pnpm build and pnpm preview, the button above the nav rail can be clicked and the width of the nav rail increases and decreases.

Screenshots or Videos

No response

Platform
  • OS: Linux
  • Browser: Chrome (headless + interactive)
  • solid-js / @solidjs/web / @solidjs/signals: 2.0.4 (first found and
    reproduced on 2.0.3 — both versions behave identically)
  • vite 8.3.8, @solidjs/vite-plugin 3.0.1, Node 26
Additional context
  • Instrumenting getNextChildId on both the SSR bundle and the client chunk
    shows the server consuming ids the client never allocates, and every later
    hydration key in that owner branch shifting.
  • Patching only the server-side reservation (removing getNextChildId from
    server Show) over-shifts in the other direction, and mirroring the
    reservation on the client does not realign the trees either — the two
    compilers create the Show components in different orders, so the id
    protocols appear to have diverged beyond a single off-by-one.
  • Hand-written synthetic repros of the same chain produce the same warnings
    but self-heal after hydration (a later render pass lands on the server
    nodes by coincidence); the death needs the real tree's reservation
    density, which is why the linked repo uses the real component sources.
    Within that tree the death is insensitive to size and content: the app's
    full navigation layout, the rail alone, the rail with zero navigation
    items, the rail without its unrendered fab branch (a keyed <Show> with
    function children — that form consumes no server id when false, unlike
    non-keyed inline <Show>; the same holds for <For> with empty data, on
    both sides), and the tree peeled component boundary by component boundary
    (removing dead code and client-only wiring from the app's original tree,
    then inlining components of the button chain into the menu button).
    Two structural findings from the peeling: (a) a component boundary
    itself is a protocol participant
    — flattening a component into its
    parent while keeping its template merges the child elements into the
    parent's template chunk and drops hydration-key reservations outright,
    which plain nested elements in the same template don't; during the
    flattening every remaining <Show> was kept — including never-rendered
    label/outline branches, which still reserve — each step renumbered the
    keys below and shrank the unclaimed set and the detached-clone count
    (sm-button loses its standalone key when merged into its wrapper's
    template chunk), and in dev and production the click stayed dead after
    every step; (b) passing ariaLabel/ariaLabelSelected instead of
    tooltip titles on the menuButton removes the tooltip subtree
    (div.anchor, sm-tooltip, sm-plain-tooltip) from the server render
    outright, shrinks the unclaimed set 7→5 nodes and the detached clones
    7→4 (keys renumber, 001008c220→001008c30) — and the click still
    stays dead. All of these fail the same way.
  • The reproduction is maximally sensitive to exactly one remaining
    component boundary: MaterialTooltip (+ MaterialPlainTooltip). In
    the linked repro the menuButton passes only aria-labels, so the
    tooltip component's internal <Show when={props.tooltip !== void 0}>
    takes its fallback — it renders nothing extra, and the served HTML
    contains no tooltip markup at all. Deleting the two tooltip components
    and unwrapping their element heals the repro completely (re-verified on
    2.0.4): 0 hydration key misses, 0 detached clones, and the menu button
    is interactive in both dev and the production build. Keeping the
    components — rendered or not — keeps the chain dead. This brackets the
    mechanism precisely: the server-side id reservations accumulated across
    the tree keep the client's claim sequence behind the server's by exactly
    the headroom one template-chunk boundary covers, and the client's later
    render passes absorb the rest only when that boundary disappears.
  • Production builds hide the warnings (dev-only), but the divergence and the
    dead elements occur there too — verified with pnpm build && pnpm preview (same unclaimed server nodes, same dead click, zero warnings).
  • Baseline fingerprints on 2.0.4, for diffing your own run: the dev
    hydration key misses are 19h0, 19h20, 19h24, 19h270, 19h2730
    against the server's (never-claimed) 19e0, 19e20,
    19e24, 19e270, 19e2730 on the menu-button chain, byte-identical
    across loads and versions; production keys follow the same family
    (_hk=001008c1 on the menu button's icon-button wrapper).
  • Workaround known to the app that surfaced this (workaround only, not a
    fix): keep the affected interactive element out of the server render and
    the hydration pass by mounting it behind an onHydrationEnd gate — the
    rail hydrates fine and the button mounts live right after hydration,
    but proper claiming with the server's id protocol remains broken.
Lingua principale
TypeScript
Stelle
37k
Fork
1.2k
Merge medio
8h 43m
PR unite (30g)
365

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.