Next.js Discord

Discord Forum

Issue with next/link

Unanswered
West African Lion posted this in #help-forum
Open in Discord
West African LionOP
Hi, i get this error :

Warning: validateDOMNesting(...): <html> cannot appear as a child of <body>.
html

Only after i change page with link. If i reload this error is gone.

Here an example of code :

My "/" root layout :
export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="en">
      <body className={inter.className}>
        <ThemeProvider attribute="class" defaultTheme="dark">
          <ModelProvider>{children}</ModelProvider>
          <Toaster richColors expand={true} />
        </ThemeProvider>
      </body>
    </html>
  );
}


My documents route layout :
export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <body className={inter.className}>{children}</body>
    </html>
  );
}


I get the error and the theme is not working and need a page reload to work correctly. With a page reload the error disappear

3 Replies