react hydration_error ai_generated true

Warning: Text content did not match. Server: 'X' Client: 'Y'

ID: react/text-content-mismatch

Also available as: JSON · Markdown
88%Fix Rate
90%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
18 active

Root Cause

SSR hydration mismatch. Server and client render different text. Common: dates, random values, browser APIs.

generic

Workarounds

  1. 95% success Use useEffect for browser-only values (dates, localStorage, window size)
    const [time, setTime] = useState('');
    useEffect(() => setTime(new Date().toLocaleString()), []);

    Sources: https://react.dev/reference/react/useEffect

  2. 85% success Use suppressHydrationWarning only on the specific element with dynamic content
    Use suppressHydrationWarning only on the specific element with dynamic content

    Sources: https://react.dev/reference/react-dom/client/hydrateRoot

  3. 88% success Ensure server and client use the same data — pass SSR data via props, not new fetches
    // Serialize SSR data into the HTML for client hydration:
    // Server renders a script tag with: window.__DATA__ = JSON.stringify(data)
    // Client: hydrateRoot(el, <App data={window.__DATA__} />)

    Sources: https://react.dev/reference/react-dom/server

Dead Ends

Common approaches that don't work:

  1. suppressHydrationWarning on every element 70% fail

    Hides the warning but the mismatch still causes visual flicker

  2. Disable SSR entirely 65% fail

    Loses SEO and initial load performance

Error Chain

Frequently confused with: