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

Offen
#190 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
68/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
react, typescript
Bereich
frontend, testing

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
TypeScript
Sterne
640
Forks
32
Ø Merge
1 Std. 15 Min.
Gemergte PRs (30 T.)
7

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus TanStack/redact

Alle Issues in TanStack/redact

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.