SSR adds px to numeric CSS custom properties, causing a hydration mismatch
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 20/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- react, typescript
調査の方向性
Read packages/redact/src/server/escape.ts and the linked test tests/ssr-custom-property-styles.test.tsx; compare how styleToString handles numeric values with how browser rendering treats keys beginning with --. The issue also proposes defaulting root.re in dom/root-internal.ts to reportRecoverableError. Tests already pass with the proposed changes on the linked branch, so check whether that work has been adopted before picking this up.
索引モデルが issue の本文から書いたものです。
説明
Bug
During SSR, numeric CSS custom properties get a px unit:
renderToString(<span style={{ '--h': 262 } as React.CSSProperties} />)
// Redact: <span style="--h:262px;"></span>
// React: <span style="--h:262"></span>
The browser renderer leaves custom properties unitless (--h: 262), so hydrateRoot hits Hydration mismatch on <span> for "style" and client-renders the whole root again.
Version: @tanstack/redact 0.3.1 (also on main at f61f721).
Seen in: a TanStack Start app with product logos styled style={{ '--h': hue }} and color: hsl(var(--h) 45% 50%).
- 516 of 539 elements on
/were recreated after load, and LCP went from ~52 ms to ~108 ms. - Until hydration finished, the logos had no colour, because
hsl(262px …)is invalid.
Passing the value as a string (String(hue)) avoids it.
Cause: styleToString in packages/redact/src/server/escape.ts applies the numeric px rule to keys starting with -- as well. setStyleProperty in dom/[dom.ts](https://github.com/home/fak3/developer/dom/dom.ts) and React both skip custom properties.
Related: mismatch fallback is silent without onRecoverableError
With no onRecoverableError passed to hydrateRoot, this mismatch produced no console output at all in production; the page just re-rendered. React's default reports these through reportError. Redact already does the same for uncaught render errors (dom/[reconcile.ts](https://github.com/home/fak3/developer/dom/reconcile.ts)), so defaulting root.re to it would make this kind of bug visible. I found this one only by patching the bundle.
Fix
Both changes, with tests and a changeset, are on a branch you're welcome to take:
https://github.com/fakelozic/redact/commit/1ef30f4ed182d0a99f3a62ce01547893f415556c
server/escape.ts: keys starting with--keep their value as written. One-line change.dom/[root-internal.ts](https://github.com/home/fak3/developer/dom/root-internal.ts):re: options.onRecoverableError ?? reportRecoverableError, which usesreportErrorand falls back toconsole.error.tests/[ssr-custom-property-styles.test.tsx](https://github.com/home/fak3/developer/tests/ssr-custom-property-styles.test.tsx): the new tests fail onmainand pass with the fix.
pnpm test (2131 passed), pnpm test:types and pnpm size:check (Node 24.22.0) all pass. The repo only accepts pull requests from collaborators, so I couldn't open a PR.
- 主要言語
- TypeScript
- スター
- 581
- フォーク
- 28
- 平均マージ
- 13時間 48分
- マージ済み PR(30日)
- 45
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
TanStack/redact のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
TanStack/redact#142 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 1〜2日 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
メンテナーはふだん 1 日以内に返信
TanStack/redact の issue をすべて見る
似ている issue
-
inference/go type/feature
難易度 1/5 1〜3時間 初心者へのやさしさ 72/100
anomalyco/opencode#65148 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
truapi-release
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
paritytech/product-sdk#529 ·
メンテナーはふだん 1 日以内に返信
-
Add: Mansudae TVオープンapproved check:passed streams:add
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
メンテナーはふだん 1 日以内に返信
-
[Perf] Canvas layer composition is quadratic: splitRenderLayers re-copies the node array per nodeオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
devlikeapro/waha#2369 ·
メンテナーはふだん 5 日以内に返信