Skip to content

Commit

Permalink
updates per review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
housseindjirdeh committed Jun 9, 2022
1 parent 46e70e7 commit 54984ff
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions errors/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,10 @@
"title": "sharp-version-avif",
"path": "/errors/sharp-version-avif.md"
},
{
"title": "script-in-document-page",
"path": "/errors/no-script-in-document-page.md"
},
{
"title": "before-interactive-script-outside-document",
"path": "/errors/no-before-interactive-script-outside-document.md"
Expand Down
29 changes: 29 additions & 0 deletions errors/no-script-in-document-page.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Script component inside \_document.js

> ⚠️ This error is not relevant in versions 12.1.6 or later. Please refer to the updated [error message](https://nextjs.org/docs/messages/no-before-interactive-script-outside-document).
#### Why This Error Occurred

You can't use the `next/script` component inside the `_document.js` page in versions prior to v12.1.6. That's because the `_document.js` page only runs on the server and `next/script` has client-side functionality to ensure loading order.

#### Possible Ways to Fix It

If you want a global script, instead use the `_app.js` page.

```jsx
import Script from 'next/script'

function MyApp({ Component, pageProps }) {
return (
<>
<Script src="/my-script.js" />
<Component {...pageProps} />
</>
)
}

export default MyApp
```

- [custom-app](https://nextjs.org/docs/advanced-features/custom-app)
- [next-script](https://nextjs.org/docs/basic-features/script#usage)

0 comments on commit 54984ff

Please sign in to comment.