docs: clarify beforeInteractive placement for root layouts - #97643
Merged
Conversation
Contributor
Tests PassedCommit: 305d23e |
Contributor
Stats skippedCommit: 305d23e |
| <AppOnly> | ||
|
|
||
| `beforeInteractive` scripts must be placed inside the root layout (`app/layout.tsx`) and are designed to load scripts that are needed by the entire site (i.e. the script will load when any page in the application has been loaded server-side). | ||
| Scripts with the `beforeInteractive` strategy must be placed inside a [root layout](/docs/app/api-reference/file-conventions/layout#root-layout), any layout without a `layout.js` above it, such as `app/layout.tsx` or `app/[locale]/layout.tsx`, and are designed to load scripts that are needed by the entire site (i.e. the script will load when any page in the application has been loaded server-side). |
Contributor
There was a problem hiding this comment.
, any layout without a layout.js above it,
this makes it sound like its root layout OR any layout when actually this is just the definition of a rootlayout? Maybe it can be in (which is any layout without a layout.js above it) or just remove and stick with the link only
| --- | ||
|
|
||
| > Prevent usage of `next/script`'s `beforeInteractive` strategy outside of `app/layout.jsx` or `pages/_document.js`. | ||
| > Prevent usage of `next/script`'s `beforeInteractive` strategy outside of a root layout or `pages/_document.js`. |
Contributor
There was a problem hiding this comment.
should this link to the root layout def as above?
Contributor
There was a problem hiding this comment.
i guess this is pages so its fine?
| ### App Router | ||
|
|
||
| If you want a global script, and you are using the App Router, move the script inside `app/layout.jsx`. | ||
| If you want a global script, and you are using the App Router, move the script inside a [root layout](/docs/app/api-reference/file-conventions/layout#root-layout), any layout without a `layout.js` above it. |
Contributor
There was a problem hiding this comment.
Aha, the link is here 🤔
aurorascharff
approved these changes
Aug 21, 2026
icyJoseph
marked this pull request as ready for review
August 21, 2026 09:51
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #97602