not-found.tsx does not render <Script> elements defined in layout.tsx when running in dev mode
Verify canary release
- [X] I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: linux
Arch: x64
Version: #22 SMP Tue Jan 10 18:39:00 UTC 2023
Binaries:
Node: 16.17.0
npm: 8.15.0
Yarn: 1.22.19
pnpm: 7.1.0
Relevant Packages:
next: 13.4.12
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
typescript: 5.1.6
Next.js Config:
output: N/A
Which area(s) of Next.js are affected? (leave empty if unsure)
No response
Link to the code that reproduces this issue or a replay of the bug
https://codesandbox.io/p/sandbox/youthful-lalande-hdhslk
To Reproduce
- Open https://codesandbox.io/p/sandbox/youthful-lalande-hdhslk sandbox
- Open dev tools Console tab
- Click the "Non-existent page" link on the homepage
- Observe the following error in the console:
Warning: Prop
dangerouslySetInnerHTMLdid not match. Server: "" Client: "(self.__next_s=self.__next_s||[]).push([0,{"children":"\n console.log(\"test\");\n "}])" script Script head html Component@ RedirectBoundary Component@ NotFoundBoundary DevRootNotFoundBoundary PureComponent@ HotReload Router Component@ ErrorBoundary AppRouter ServerRoot RSCComponent PureComponent@ Root
Describe the Bug
not-found.tsx page does not render <Script> elements defined in layout.tsx when running in dev mode.
Expected Behavior
<Script> elements defined in the root layout should execute the same way as on all other pages.
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
I’m having this issue as well. I have a RootLayout with some scripts with beforeInteractive. One of them assigns env variables to window. It works well on other app dir pages but not on the not-found.tsx root page.
Same here, only <script> react tags with async attr would load
This issue has been automatically marked as stale due to inactivity. It will be closed in 7 days unless there’s further input. If you believe this issue is still relevant, please leave a comment or provide updated details. Thank you.
This issue has been automatically closed due to inactivity. If you’re still experiencing a similar problem or have additional details to share, please open a new issue following our current issue template. Your updated report helps us investigate and address concerns more efficiently. Thank you for your understanding!