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

オープン
#5,226 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@leo7martins がすでに取り組んでいます。

2026年11月27日 から。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
javascript, typescript, vite
領域
frontend, testing

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.
主要言語
TypeScript
スター
37k
フォーク
1.2k
平均マージ
8時間 43分
マージ済み PR(30日)
365

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

solidjs/solid のほかの issue

solidjs/solid の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。