Skip to content

Rendering content (e.g. text) outside of an element directly underneath <body> causes a hydration error (when <body> is defined in page.tsx, not layout.tsx) #76815

Answered by samcx
rik-iso asked this question in Help
Discussion options

You must be logged in to vote

@rik-iso The correct convention is to have the <html> and <body> in the Root Layout → https://nextjs.org/docs/app/getting-started/layouts-and-pages#creating-a-layout.

on-recoverable-error.js:28 Uncaught Error: Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:

- A server/client branch `if (typeof window !== 'undefined')`.
- Variable input such as `Date.now()` or `Math.random()` which changes each time it's called.
- Date formatting in a user's locale which doesn't match the server.
- External changing data without sending a snapshot of it along with the HTML…

Replies: 6 comments 2 replies

This comment was marked as off-topic.

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by samcx
Comment options

You must be logged in to vote
2 replies
@rik-iso
Comment options

@samcx
Comment options

samcx Mar 6, 2025
Maintainer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
4 participants
Converted from issue

This discussion was converted from issue #76715 on March 04, 2025 20:15.