v0 + shadcn hydration error: stop the server HTML from disagreeing with the client

By AI App Medic · Updated · v0 · Next.js · shadcn · React

You generate a Next.js app in v0, often with shadcn/ui, and the page looks fine for a moment, then React logs: Text content does not match server-rendered HTML, or Hydration failed because the server rendered HTML didn't match the client. The UI may flash, a theme may jump, or a dialog may flicker. This is not a random Vercel outage. The HTML Next.js sent from the server and the HTML React produced in the browser on the first pass were not the same.

What hydration is checking

On a Next.js App Router page, the server renders HTML and the browser then "hydrates" it: React attaches events and takes over, assuming the tree already on the page is the tree it would have rendered. If a component reads window, localStorage, the current time, or a random value during that first render, the server (which has none of those) and the client disagree.

"use client" does not mean "render only in the browser". Client components are still pre-rendered on the server unless you explicitly load them with ssr: false. shadcn components are client components. They have to be just as deterministic on the first paint as the rest of the tree.

Step 1: find the first node that differs

  1. Open the app with DevTools > Console. React's message usually names a component and shows the two texts or the unexpected tag.
  2. Repeat in a private window with extensions disabled. Grammar and dark-mode extensions are frequent false alarms.
  3. If the error appears only in production, run npm run build && npm start locally so you are not chasing a dev-only warning.

Common first differences in v0 and shadcn apps:

Step 2: render a stable first output, then update

Move anything that depends on the browser into an effect, and render a placeholder that is the same on the server and the first client pass:

"use client";

import { useEffect, useState } from "react";

export function ClientOnly({ children, fallback = null }) {
  const [mounted, setMounted] = useState(false);
  useEffect(() => { setMounted(true); }, []);
  if (!mounted) return fallback;
  return children;
}

Use that around a widget that must read localStorage or window. The fallback can be a skeleton with the same size, so the layout does not jump. For a single date, format it in an effect, or pass a preformatted string from the server as a prop.

If you need to skip server rendering for a heavy, browser-only chart:

import dynamic from "next/dynamic";

const Chart = dynamic(() => import("@/components/chart"), { ssr: false });

Do not mark the whole page ssr: false just to silence the error. You lose the HTML that makes the first load fast.

Step 3: fix the theme provider the way Next.js expects

shadcn's dark mode is usually next-themes. The pattern that avoids a mismatch is: the server renders a default (often light, or a neutral class), a tiny inline script may set the class before paint, and the provider is told not to update during SSR. Follow the current next-themes App Router example, including suppressHydrationWarning on the <html> tag if their docs still recommend it for that one node, and attribute="class" to match how Tailwind's dark: classes work.

If you wrote your own toggle that reads localStorage in the component body, switch it to the provider. Two competing theme scripts will keep causing a mismatch.

Step 4: clean up IDs, dates, and invalid markup

When the build is also failing

A hydration warning shows up in the running app. If Vercel never deploys, that is a compile problem, not hydration. Use Cursor app Vercel build failed for TypeScript and install errors. After the mismatch is gone, the first paint should stay put, with no flash of the wrong theme or the wrong text, and the console should be quiet in a private window.

FAQ

I already added use client. Why do I still get a hydration error?

In the App Router, use client means the component can use state and effects. It does not skip server rendering. The server still renders the component's first output, and that output must match the browser's first output.

Is suppressHydrationWarning a fix?

It is a narrow escape hatch for a known difference, such as a timestamp, on a specific text node. It will not help if you sprinkle it on a large tree, and it can hide a real bug.

Could an extension be causing it?

Yes. Browser extensions inject nodes into the page and can trip the warning on your machine only. Check in a private window with extensions disabled before you rewrite the layout.

Related guides