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

Aperta
#190 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
react, typescript
Ambito
frontend, testing

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
640
Fork
32
Merge medio
1h 15m
PR unite (30g)
7

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TanStack/redact

Tutte le issue di TanStack/redact

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.