Your Next.js app shows this in the console, usually after you deploy or add a new component:
Error: Hydration failed because the initial UI does not match what was rendered on the server.
Enter fullscreen mode
Exit fullscreen mode
or "Text content does not match server-rendered HTML". The page may flash, break, or work after a refresh. Here is what it means, and the one "fix" that creates a security problem.
What it means
Next.js renders your page to HTML on the server, then React "hydrates" it in the browser: it attaches events and expects the same markup. If the first browser render produces different HTML than the server sent, React reports a hydration mismatch.
The 6 usual causes
Browser-only values in render. window , localStorage , navigator or document used while rendering give different results on the server and client.
Time and randomness. new Date() , Date.now() or Math.random() in the render output differ between the two renders.
Invalid HTML nesting.…