Fix BugsIntermediate

Fixing React Hydration Errors

What hydration errors mean and how to fix them. The most common cause of 'content does not match' errors in Next.js and React SSR apps.

What is hydration?

When you use server-side rendering (SSR), React first renders your component on the server as HTML. The browser displays this HTML immediately (fast initial load). Then React 'hydrates' — it attaches event handlers and makes the HTML interactive. Hydration errors occur when the server HTML doesn't match what React tries to render on the client.

Common causes

Using browser-only APIs during render: Date.now(), window.innerWidth, localStorage. These don't exist on the server, so the server renders different content than the client. Conditional rendering based on auth state that's only available client-side. Using random values or time-dependent content. HTML nesting violations (like a <p> inside a <p>).

How to fix them

For browser-only values: render a default on the server and update client-side with useEffect. For auth-dependent content: use Suspense boundaries or loading states. For time-dependent content: use suppressHydrationWarning on the specific element (last resort). For HTML violations: fix the nesting — use the browser's DOM inspector to find invalid structures.

The useEffect pattern

The safest way to render browser-only content: start with a server-safe default, then update after mount. Use a state variable initialized to the safe default, and update it in useEffect. This ensures the server and client render the same content initially, then the client updates to the correct value.

Need help with this?

Our team handles fix bugs for AI-built apps every day. Get a fixed quote within 24 hours.

Start with a self-serve audit

Get a professional review of your app at a fixed price.

Security Scan

Black-box review of your public-facing app. No code access needed.

$19
  • OWASP Top 10 checks
  • SSL/TLS analysis
  • Security headers
  • Expert review within 24h
Get Started

Code Audit

In-depth review of your source code for security, quality, and best practices.

$19
  • Security vulnerabilities
  • Code quality review
  • Dependency audit
  • AI pattern analysis
Get Started
Best Value

Complete Bundle

Both scans in one package with cross-referenced findings.

$29$38
  • Everything in both products
  • Cross-referenced findings
  • Unified action plan
Get Started

100% credited toward any paid service. Start with an audit, then let us fix what we find.

Related technologies

Need help with your app?

Tell us about your project. We'll respond within 24 hours with a clear plan and fixed quote.

Tell Us About Your App