Skip to content
VibecodeZero

Hydration failed in your AI-built app: what it means and how to fix it

Updated First published

On this page (4)
  1. Symptom
  2. Cause
  3. Prompt to paste
  4. How not to burn credits

Symptom

A red error or warning in the browser console or in the tool's preview, with text like Hydration failed because the initial UI does not match what was rendered on the server, or Text content does not match server-rendered HTML. Sometimes a piece of text flickers or changes right after the page loads, or the app stops responding to clicks.

Cause

When someone opens a page, some apps don’t wait for the browser to build everything. The server builds the page first and sends it ready, so it appears quickly. Then the browser loads the app’s code and connects it to that page, so the buttons and forms work. That connection step is called hydration.

For hydration to work, the first version the browser draws has to match the server’s version exactly. If one word, number or block is different, React, the library behind Next.js apps, stops and reports the mismatch. That’s the hydration error.

This isn’t specific to one tool. It shows up in Next.js style apps built with any vibe coding tool, and in code written with an AI assistant in an editor.

Common causes

  • Current date or time. Code like Date.now() or new Date() gives one value on the server and another, a moment later, in the browser.
  • Random values. Math.random() gives a different number each time it runs, so the server and the browser never agree.
  • Formats that depend on the computer. toLocaleString() without a fixed language or time zone can format a date or a price one way on the server and another way on your computer.
  • Browser data read too early. The server has no localStorage and no window. If the page reads them while it is first drawn, the server and the browser end up with different content. When the server crashes on this instead, you see localStorage is not defined.
  • Browser extensions. Translators, password managers and similar extensions sometimes add things to the page before the app connects to it.
  • HTML in the wrong place. Some blocks can’t go inside others, like a div inside a p. The browser rearranges them and the page no longer matches.

You don’t need to know which one it is. The error message usually points to it, and the AI can read it.

Beginner steps

  1. Open the console. Press F12, or right-click the page and choose Inspect, then open the Console tab. Reload the page.
  2. Copy the full error. Copy everything in red about hydration, including any part that shows two different texts side by side.
  3. Rule out extensions. Open the page in a private window with extensions off. If the error is gone, you can stop here.
  4. Restore if it’s looping. If the AI already tried to fix it several times and the app got worse, go back to the last version that worked before you continue.
  5. Paste the prompt. Use the prompt on this page with the full error and the page where it happens.
  6. One fix at a time. Check the page after each fix. If a new error appears, send that one next, by itself.

If the AI says the problem is fixed but the warning keeps coming back, read The AI says it fixed it, but the error is still there. If the page doesn’t show anything at all, see My app shows a blank screen. New to the term local storage? The glossary explains it in one sentence.

If you run the app on your own computer and it doesn’t start at all, the terminal usually shows a different error. See Port 3000 is already in use or Cannot find module.

Prompt to paste

Copy the text below, replace what’s in brackets and send it in the chat of the tool you’re using.

Paste into the AI
My app shows a hydration error. The full message is:
[paste the whole error, including the part that shows the different text, if there is one]

It happens on this page: [the page or screen where it appears].
This started after I asked: [the last request you made, if you remember it].

Find what renders differently on the server and in the browser on this page. Check for things like dates and times, random values, number or date formats without a fixed language, and code that reads localStorage, window or document during the first render.
Fix only the cause of this error, without changing anything else in the app. Then tell me in one sentence what the problem was.

How not to burn credits

  • Before you send anything, open the app in a private or incognito window with your browser extensions turned off. If the error goes away, an extension was changing the page and there is nothing to fix in your code.
  • Send the whole error message, the page where it happens and your last request in a single message. Several short messages like "still broken" each use part of your limit.
  • Ask for one fix at a time. If the AI changes a lot of files to fix one hydration error, stop and ask it to explain the cause first, without changing code.
  • If two or three attempts don't fix it, go back to the last version that worked, using the tool's version history, and ask again for the change that caused the problem, in smaller parts.

How Lovable counts credits, and what the free plan includes: Lovable credits explained.

Questions people ask

What does hydration mean, in plain English?

In apps built with Next.js and similar setups, the server sends a ready-made page so it shows up fast. Then the browser loads the app's code and attaches it to that page so the buttons work. That attaching step is called hydration. For it to work, the page the browser draws first has to be exactly the same as the one the server sent.

What usually causes a hydration error?

Anything that comes out different on the server and in the browser. The most common ones are showing the current date or time with Date.now() or new Date(), random values from Math.random(), formatting dates or numbers with toLocaleString() without a fixed language or time zone, reading localStorage or window while the page is first drawn, and browser extensions that add things to the page. Putting one block inside another where HTML doesn't allow it, like a div inside a p, can also cause it.

How do I know if a browser extension is the cause?

Open the same page in a private or incognito window with extensions turned off, or in another browser. If the error disappears there, an extension like a translator, password manager or ad blocker was changing the page. Your visitors may not have that extension, so the app itself is probably fine.

Is a hydration error serious?

Sometimes it's only a warning and the page still works. Other times parts of the page stop responding or show the wrong text for a moment. Check whether the app actually works for a user. If it does, you can fix it calmly. If buttons stop working, fix it before you publish.

What should I ask the AI?

Paste the full error and ask it to find what renders differently on the server and in the browser, and to fix only that. A good fix usually shows the changing part, like the time or saved data, only after the page has loaded in the browser. Ask the AI not to hide the warning without fixing the cause.

Does this happen in Lovable too?

This error comes from apps where the server draws the page first, like Next.js apps. It can show up in code from any AI tool that builds that kind of app. If your app doesn't render pages on the server, you will usually see other errors instead, like a blank screen.

New guides by email. An email when we publish a new guide, error fix or chapter, in plain English. Subscribe