← All errors · Next.jsReact & Next.js rendering errors

Hydration failed because the initial UI does not match what was rendered on the server

Exact error

Error: Hydration failed because the initial UI does not match what was rendered on the server.

What it means

React rendered HTML on the server, then rendered again in the browser and got a different result. React cannot attach to mismatched markup, so it throws during hydration.

Likely causes

How to fix it

  1. Check the console for the specific element React complains about and fix invalid nesting first.

  2. Move browser-only values into useEffect so the first client render matches the server:

    'use client';
    import { useEffect, useState } from 'react';
    
    export default function Clock() {
      const [now, setNow] = useState(null);
      useEffect(() => setNow(new Date().toLocaleTimeString()), []);
      return <span>{now ?? ''}</span>;
    }
  3. For a component that can only run in the browser, disable SSR for it:

    import dynamic from 'next/dynamic';
    const Map = dynamic(() => import('./Map'), { ssr: false });
  4. For an unavoidable single-element difference (e.g. a timestamp), use suppressHydrationWarning on that element only:

    <time suppressHydrationWarning>{new Date().toISOString()}</time>
  5. Retest in an incognito window to rule out browser extensions.

Still stuck after trying this? Get it fixed for $49, or you don't pay.

Prevent this next time

Guide: catch outages before your users do.

Tools that help:

Some links on this page are affiliate links: if you sign up or buy through them, FixStack may earn a commission at no extra cost to you. Learn more.

FAQ

What does "Hydration failed because the initial UI does not match what was rendered on the server" mean?

React rendered HTML on the server, then rendered again in the browser and got a different result. React cannot attach to mismatched markup, so it throws during hydration.

What usually causes it?

Using browser-only values during render (window, localStorage, Date.now(), Math.random()). Invalid HTML nesting, e.g. a <div> inside a <p>, or <a> inside <a>. Locale/time-zone dependent formatting (toLocaleString) differing between server and client. Browser extensions modifying the DOM before React hydrates.

How do I fix it?

1. Check the console for the specific element React complains about and fix invalid nesting first. 2. Move browser-only values into useEffect so the first client render matches the server: 3. For a component that can only run in the browser, disable SSR for it: 4. For an unavoidable single-element difference (e.g. a timestamp), use suppressHydrationWarning on that element only: 5. Retest in an incognito window to rule out browser extensions.

Related errors

More Next.js errors and fixes →

Tools that help

  • Railway: Deploy backends and databases; new users get $20 credit.

Some links on this page are affiliate links: if you sign up or buy through them, FixStack may earn a commission at no extra cost to you. Learn more.

Get new fixes weekly

No spam. Unsubscribe anytime. Privacy