Vite plugin with environments: ['client'] hydrates React's server HTML with Redact-format useId values, so every useId attribute mismatches (0.3.1)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 28/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- node.js, react, typescript, vite
Direzione di ricerca
Start with the Vite plugin's environment handling and the identifierStrategy option it passes, comparing it with the Next.js integration in src/next/client.ts. Reproduce the mismatch with the jsdom snippet in the issue, checking that useId output differs between _R_0_ and :r0. Done when hydration with environments: ['client'] produces React-compatible ids and reports no recoverable errors.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
With the Vite plugin set to replace the browser only, redact({ environments: ['client'] }), the server renders with React and Redact hydrates React's HTML. React's useId writes ids like _R_0_. Redact's client generates :r0 and doesn't match them, so every element whose attribute carries a useId value is a hydration mismatch, and the server's DOM is replaced.
In a TanStack Start app built this way, every server-rendered page reported Hydration mismatch. through onRecoverableError on load, because headless UI libraries (Base UI here) put useId values in id, htmlFor and aria-* attributes.
Redact already has the fix: identifierStrategy: 'react' makes the client produce React's ids, and the Next.js integration passes it (src/next/client.ts). The Vite plugin doesn't pass it when the SSR environment is left on native React, and there is no public way to opt in from a Vite app, since TanStack Start calls hydrateRoot itself.
Reproduction
// Server: real React
import { renderToString } from 'react-dom/server'
// Client: Redact
import { hydrateRoot } from '@tanstack/redact/dom-client'
function Field() {
const id = useId() // from each runtime's own 'react'
return (
<div>
<label htmlFor={id}>Email</label>
<input id={id} />
</div>
)
}
container.innerHTML = renderToString(<Field />) // React
const serverInput = container.querySelector('input')
hydrateRoot(container, <Field />, { onRecoverableError: (e) => errors.push(e.message) }) // Redact
Run in jsdom with Node 26, each side using its own runtime's createElement and useId:
| Production | Development | |
|---|---|---|
| Server HTML (React) | <label for="_R_0_"> <input id="_R_0_"> |
same |
| After Redact hydrates | <label for=":r0"> <input id=":r0"> |
same |
| Recoverable errors | Hydration mismatch. |
Hydration mismatch on <label> for "htmlFor". |
Server <input> kept |
no | no |
Passing identifierStrategy: 'react' to hydrateRoot gives _R_0_ on both sides, no errors, and keeps the server's <input>.
Expected
When the plugin leaves the server on native React (environments: ['client']), the client hydrates with React-compatible ids, as the Next.js and Vinext integrations do. Alternatively, the plugin could expose an option for it.
Related: #155 covers the same id scheme when Redact renders both sides, where ids shift with lazy timing.
Environment
@tanstack/redact 0.3.1, React 19.3.1, @tanstack/react-start 1.169.7, Vite+ 1.7.0 (Vite 8.3), Node 26.13.1.
- 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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di TanStack/redact
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
TanStack/redact#195 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
TanStack/redact#142 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di TanStack/redact
Issue simili
-
bug data-types
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
ClickHouse/clickhouse-js#1293 ·
I maintainer di solito rispondono entro 1 giorno
-
area: middleware enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
agent/quality testing
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
I maintainer di solito rispondono entro 1 giorno
-
GitHub registry install via `gh` credentials rewrites `\u0000`–`\u001f` escapes in source files to `^@`–`^_`Forse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 92/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
juspay/agent-distro#203 ·
I maintainer di solito rispondono entro 1 giorno