Skip to content

Commit

Permalink
docs: fix next/script example causing hydration errors (#63401)
Browse files Browse the repository at this point in the history
Related #51242 

React will error `In HTML, <script> cannot be a child of <html>. This
will cause a hydration error.` when `script` is rendered under `html`
directly. The examples in our docs are causing this hydration error.
Moving it under `body` tag will fix the hydration error

Closes NEXT-2834

Co-authored-by: Delba de Oliveira <32464864+delbaoliveira@users.noreply.github.com>
  • Loading branch information
huozhi and delbaoliveira authored Mar 18, 2024
1 parent 0c1a531 commit 049d127
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions docs/02-app/02-api-reference/01-components/script.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ export default function RootLayout({
}) {
return (
<html lang="en">
<body>{children}</body>
<Script
src="https://example.com/script.js"
strategy="beforeInteractive"
/>
<body>
{children}
<Script
src="https://example.com/script.js"
strategy="beforeInteractive"
/>
</body>
</html>
)
}
Expand All @@ -112,11 +114,13 @@ import Script from 'next/script'
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>{children}</body>
<Script
src="https://example.com/script.js"
strategy="beforeInteractive"
/>
<body>
{children}
<Script
src="https://example.com/script.js"
strategy="beforeInteractive"
/>
</body>
</html>
)
}
Expand Down

0 comments on commit 049d127

Please sign in to comment.