Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[2.0 RC] SSR hydration keys shift when memo()-wrapped prop getters are read before `children` through `<Dynamic>`, so the child never hydrates

已关闭
#3,797 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
58/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript
领域
frontend

调研方向

Start by tracing server-side ssrElement prop processing and how hydration keys are allocated for children; compare those allocations with the client behavior described in the report. Use the linked StackBlitz reproduction and run its install, build, and render commands, then serve build/ and toggle the signal. Done when the child claims the matching server key and updates the in-document span.

由索引模型根据 Issue 内容生成。

描述

Describe the bug

A component rendered through <Dynamic component="button"> can receive props whose values are ternaries over a logical expression. The compiler emits these as memo(() => …)() ? a : b getters. On the server, each read of such a getter creates a sync memo, and that memo takes a child id from the owner that is current during ssrElement's prop loop. That owner is the same one that later allocates the hydration key for the element's children. The getters are read before children, so the server's key for the child is shifted by the number of memo-wrapped props. The client doesn't make the same allocations, so it looks for the unshifted key.

As a result, the child misses hydration. The client builds a detached copy, the server-rendered node stays in the document with nothing bound to it, and later reactive updates to the child never reach the page.

We first saw this with Kobalte 2.0.0-alpha.2's Dialog.Trigger / DropdownMenu.Trigger (Button → Polymorphic → Dynamic). The repro below doesn't use Kobalte; it only copies Kobalte's prop layering.

Your Example Website or App

https://stackblitz.com/edit/solidjs-templates-gftulnlj?file=package.json

Steps to Reproduce the Bug or Issue
  1. npm install && node build.mjs && node render.mjs
  2. Serve build/ statically and open index.html.
  3. In the console, run toggle().
Expected behavior

Expected behavior:
The server gives the child the key that follows the button's key, matching the client:

<button _hk=50 type="button"><span _hk=51 id="label">label</span></button>

The client claims <span _hk=51>, and after toggle() the in-document span gets data-on.

Actual behavior:
The server skips three ids before the child:

<main _hk=0><button _hk=50 type="button"><span _hk=54 id="label">label</span></button></main>

The client (development build) warns:

Hydration key miss for "51": no server-rendered element carries this key (template: <span id=label>label). A detached element was created instead; its subtree will not appear in the document or become interactive. …
Hydration completed with 1 unclaimed server-rendered node(s): <span _hk="54" id="label">label</span>

After toggle(), the span in the document is still _hk="54" with no data-on. The update went to the detached client copy.

Screenshots or Videos

No response

Platform
  • OS: macOS
  • Browser: Chrome
  • Version: Version 154.0.8037.97 (Official Build) (x86_64)
Additional context

None.

主要语言
TypeScript
星标
36.1k
派生
1.1k
平均合并
13 小时 13 分钟
30 天内合并 PR
306

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

solidjs/solid 的其他 Issue

查看 solidjs/solid 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。