SVG: vectorEffect breaks hydration, and streamed Suspense inside <svg> lowercases attributes

未關閉
#121 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@azizbecha 已經在處理了。

開始於 2026年10月31日。

  • #122 來自 @azizbecha —— 未關閉

評估

難度
4/5
預估耗時
3-5 天
新手友好度
25/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
react, typescript
領域
frontend

研究方向

Start with attributeName() in packages/redact/src/core/attributes.ts, which only hyphenates clip, fill and stroke props, so vectorEffect needs mapping to vector-effect. The streaming gap is separate: the boundary content is walked without SVG context, and the <div> placeholder breaks out of <svg>, so the Suspense path needs its own investigation. Done means server HTML keeps vector-effect and preserveAspectRatio, and hydration inside <svg> matches React. Related PRs #96 and #103 overlap these paths, so check them first.

由索引模型根據 Issue 內容生成。

描述

Version: @tanstack/redact 0.2.3 and main (37c051c). Baseline: react / react-dom 19.3.1. Browser: headless Chrome 154.

preserveAspectRatio and vectorEffect were both lowercased up to 0.2.0. #76 fixed the common preserveAspectRatio case in 0.2.1, but two gaps remain, and React handles both correctly.

Path preserveAspectRatio vectorEffect
renderToString Correct Emits vectorEffect (React emits vector-effect)
After Chrome parses that HTML Correct Becomes vectoreffect, ignored
Hydration Clean, server nodes kept Mismatch, server <main> replaced
createRoot Correct, including updates vectorEffect, ignored
Streamed Suspense directly inside <svg> preserveaspectratio, ignored vectoreffect, ignored

Without an onRecoverableError handler, the hydration failure logs nothing.

1. vectorEffect is never mapped to vector-effect, and this breaks hydration

attributeName() in packages/redact/src/core/attributes.ts only hyphenates SVG props starting with clip, fill or stroke, so vectorEffect passes through unchanged. On the client the browser ignores it. On the server, the HTML parser lowercases it to vectoreffect because it isn't a known SVG attribute name. Hydration then looks up vectorEffect, doesn't find it, and discards the boundary:

Hydration mismatch on <path> for "vectorEffect".
const tree = h(Suspense, { fallback: null },
  h('main', null,
    h('svg', null, h('path', { d: 'M0 0L9 9', vectorEffect: 'non-scaling-stroke' }))))

The computed vector-effect is none under Redact and non-scaling-stroke under React. This differs from what #81 describes for presentation attributes ("hydration reports nothing"): in a real browser, the parser's lowercasing makes hydration fail for this prop.

Workaround: style={{ vectorEffect: 'non-scaling-stroke' }} renders correctly and hydrates cleanly.

2. Streamed Suspense directly inside <svg> loses the SVG context

// Late suspends until after the shell has flushed
h('main', null,
  h('svg', { viewBox: '0 0 9 9' },
    h(Suspense, { fallback: null }, h(Late))))
// Late renders <symbol preserveAspectRatio="none" />

Redact emits:

<svg viewBox="0 0 9 9"><!--$?0--><div id="B:0"></div><!--/$--></svg>
...
<div hidden id="S:0"><symbol preserveaspectratio="none"></symbol></div>
  • The boundary's content is walked with no SVG context, so attributeName() takes its lowercase fallback.
  • The <div> placeholder makes the HTML parser break out of the <svg>, and the segment is parsed in an HTML <div>. After reveal, the <symbol> is a child of <main>, in the HTML namespace.

Under React the same tree reveals inside the <svg>, in the SVG namespace, with preserveAspectRatio intact. A boundary outside the <svg> is unaffected under Redact, which is also the workaround.

Related

  • #42: the original lowercasing report. Its preserveAspectRatio case is fixed outside streaming.
  • #81 / #96: the wider set of SVG presentation attributes. From reading the diff, #96 would also map vectorEffect. I haven't run it.
  • #103: streamed insertion context for tables, SVG and MathML. From reading the diff, it targets the second gap. I haven't run it, and it currently has merge conflicts.
主要語言
TypeScript
星號
640
分支
32
平均合併
1 小時 15 分鐘
30 天內合併 PR
7

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

TanStack/redact 的其他 Issue

查看 TanStack/redact 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。