Unverified Commit 049d127e authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

docs: fix next/script example causing hydration errors (#63401)

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: 's avatarDelba de Oliveira <32464864+delbaoliveira@users.noreply.github.com>
parent 0c1a531e
...@@ -96,11 +96,13 @@ export default function RootLayout({ ...@@ -96,11 +96,13 @@ export default function RootLayout({
}) { }) {
return ( return (
<html lang="en"> <html lang="en">
<body>{children}</body> <body>
<Script {children}
src="https://example.com/script.js" <Script
strategy="beforeInteractive" src="https://example.com/script.js"
/> strategy="beforeInteractive"
/>
</body>
</html> </html>
) )
} }
...@@ -112,11 +114,13 @@ import Script from 'next/script' ...@@ -112,11 +114,13 @@ import Script from 'next/script'
export default function RootLayout({ children }) { export default function RootLayout({ children }) {
return ( return (
<html lang="en"> <html lang="en">
<body>{children}</body> <body>
<Script {children}
src="https://example.com/script.js" <Script
strategy="beforeInteractive" src="https://example.com/script.js"
/> strategy="beforeInteractive"
/>
</body>
</html> </html>
) )
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment