Vite plugin with environments: ['client'] hydrates React's server HTML with Redact-format useId values, so every useId attribute mismatches (0.3.1)
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 28/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- node.js, react, typescript, vite
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 640
- Forks
- 32
- Merge medio
- 1 h 15 min
- PR fusionados (30 d)
- 7
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de TanStack/redact
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
TanStack/redact#195 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
TanStack/redact#142 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
Todos los issues de TanStack/redact
Issues similares
-
bug data-types
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
ClickHouse/clickhouse-js#1293 ·
Los mantenedores suelen responder en 1 día
-
area: middleware enhancement good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
agent/quality testing
Dificultad 1/5 Menos de una hora Aptitud para principiantes 95/100
Los mantenedores suelen responder en 1 día
-
GitHub registry install via `gh` credentials rewrites `\u0000`–`\u001f` escapes in source files to `^@`–`^_`Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 92/100
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
juspay/agent-distro#203 ·
Los mantenedores suelen responder en 1 día