Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:
A server/client branch if (typeof window !== 'undefined').
Variable input such as Date.now() or Math.random() which changes each time it's called.
Date formatting in a user's locale which doesn't match the server.
External changing data without sending a snapshot of it along with the HTML.
Invalid HTML tag nesting.
It can also happen if the client has a browser extension installed which messes with the HTML before React loaded.
You're seeing a hydration mismatch error in your React or Next.js application. This happens when the HTML rendered on the server (SSR) doesn't match what React expects when it tries to "hydrate" (attach behavior to) that HTML on the client.
🔍 What Is Hydration?
In Server-Side Rendering (SSR), React renders your components into HTML on the server. Once this HTML is sent to the browser, React runs again on the client and attempts to associate (or hydrate) the virtual DOM with the actual DOM — without re-rendering everything from scratch.
If there's any discrepancy between the server-rendered HTML and what React expects during hydration, you get a hydration mismatch error, like:
code
Hydration failed because the server rendered HTML didn't match the client.
✅ Common Causes & Fixes
Here are the most common reasons for this error and how to fix them:
1. Conditional Rendering Based on Environment
js
if (typeof window !== 'undefined') {
// Client-only code
}
❌ Problem:
This block will not run during SSR, so the server won’t render it — but the client will. That creates a mismatch.