react
hydration_error
ai_generated
true
Warning: Prop `className` did not match. Server: "server-class" Client: "client-class"
ID: react/react-hydration-attribute-mismatch
86%Fix Rate
89%Confidence
120Evidence
2022-03-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 18 | active | — | — | — |
Root Cause
HTML attribute/prop mismatch between server-rendered HTML and client-side React hydration. Common causes: CSS-in-JS generating different classNames, browser extensions injecting attributes, conditional rendering based on window/navigator.
genericWorkarounds
-
90% success Ensure CSS-in-JS library is configured for SSR (e.g., styled-components ServerStyleSheet, emotion extractCritical)
For styled-components: use ServerStyleSheet in server rendering. For emotion: use extractCriticalToChunks. Ensure the same hash/seed is used on server and client.
Sources: https://styled-components.com/docs/advanced#server-side-rendering https://emotion.sh/docs/ssr
-
88% success Defer browser-only attribute computation to useEffect
const [className, setClassName] = useState('server-safe-class'); useEffect(() => { setClassName(computeClientClass()); }, []);
Dead Ends
Common approaches that don't work:
-
Add suppressHydrationWarning to all mismatched elements
70% fail
Suppresses the warning but the visual flicker remains as React patches the DOM. Does not fix CSS-in-JS class mismatch which causes FOUC.
-
Force client-side rendering to avoid hydration entirely
65% fail
Eliminates SSR benefits including SEO, initial load performance, and time-to-first-contentful-paint
Error Chain
Preceded by:
Frequently confused with: