The error
Hydration failed because the initial UI does not match what was rendered on the server.
Quick answer: A hydration mismatch occurs when the HTML produced on the server differs from what React produces during the first browser render.
What this error means
A hydration mismatch occurs when the HTML produced on the server differs from what React produces during the first browser render.
Start with the first application-owned file, operation, request, query, plugin, or component identified by the error. Fix the underlying failure before changing unrelated parts of the application.
Common causes
- Browser-only APIs such as window or localStorage are used during rendering.
- Time-dependent values produce different server and client output.
- HTML elements are nested incorrectly.
- Conditional rendering produces different initial content in the browser.
- A component depends on client-only state before hydration finishes.
Immediate repair pattern
'use client';
import {
useEffect,
useState
} from 'react';
export default function ClientValue() {
const [value, setValue] =
useState(null);
useEffect(() => {
setValue(
localStorage.getItem('value')
);
}, []);
if (value === null) {
return <div>Loading...</div>;
}
return <div>{value}</div>;
}
Apply the repair only when it matches the actual runtime condition shown by the complete error and application context.
Do not hide the root cause
Do not silence every hydration warning. First determine why the server and browser produced different initial HTML.
Repair checklist
- Capture the complete error and stack trace.
- Identify the first application-owned location or resource involved.
- Confirm the runtime value, state, response, or configuration reported by the error.
- Apply the smallest repair that addresses the actual cause.
- Retest both the successful path and the original failing path.
- Confirm the original error no longer occurs.
Still getting the error?
Paste the complete error and stack trace into 0-69. The matching repair engine can classify the failure and prepare specific repair steps and copy-ready code for the detected pattern.
Analyze My Next.js ErrorReference: Official platform documentation