Dev hydration omits React’s warning for an unexpected attribute on <html>

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

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

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

研究方向

Start by tracing the development hydration path used by hydrateRoot and compare its handling of unexpected attributes with the React 19.3.1 behavior described here. Use the supplied jsdom reproduction with the extra argument, then check the matching-HTML control. Done means development hydration reports the unexpected element and attribute while preserving the DOM and leaving recoverable errors unused.

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

描述

When the DOM has an extra attribute before hydrateRoot(document, …) runs, React 19.3.1 logs a development diagnostic identifying the element and attribute. Redact 0.3.1 hydrates the same document silently. We encountered this in a TanStack Start dev server with the Redact Vite plugin. The standalone reproduction below also triggers it without Vite or a browser extension.

Development runtime Matching HTML Extra data-extra="true" on <html>
React DOM 19.3.1 Quiet One console.error with an attribute diff
Redact 0.3.1 Quiet No console.error or console.warn

Both runtimes completed hydration and retained the extra attribute. Neither invoked onRecoverableError. This differs from the text mismatch in #62, where React recovers by re-rendering.

Reproduction

Install [email protected], [email protected], @tanstack/[email protected], and [email protected]. Save this as repro.mjs.

import { JSDOM } from 'jsdom'

const { window } = new JSDOM(
  '<!doctype html><html lang="en"><head></head><body><main>Home</main></body></html>'
)
for (const key of ['window', 'document', 'Node', 'Element', 'HTMLElement', 'Text',
  'Comment', 'Document', 'DocumentFragment', 'MutationObserver']) {
  globalThis[key] = window[key]
}

const redact = process.argv[2] === 'redact'
const { createElement: h } = await import(redact ? '@tanstack/redact' : 'react')
const { hydrateRoot } = await import(redact ? '@tanstack/redact/dom-client' : 'react-dom/client')
if (process.argv[3] === 'extra') document.documentElement.dataset.extra = 'true'

await new Promise(resolve => {
  const main = h('main', { ref: node => { if (node) resolve() } }, 'Home')
  hydrateRoot(document, h('html', { lang: 'en' }, h('head'), h('body', null, main)), {
    onRecoverableError: error => console.log('recoverable:', error.message),
  })
})
console.log('Hydrated. data-extra =', document.documentElement.getAttribute('data-extra'))
window.close()
NODE_ENV=development node repro.mjs react extra
NODE_ENV=development node repro.mjs redact extra

Omit extra for the matching-HTML control. React’s diff includes the line - data-extra="true".

Expected behavior

Please report unexpected DOM attributes during development hydration, with enough context to identify the element and attribute. The existing DOM can stay as it is. This would let developers diagnose SSR differences with the Redact plugin enabled.

主要語言
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 摘要。