next.js icon indicating copy to clipboard operation
next.js copied to clipboard

not-found.tsx does not render <Script> elements defined in layout.tsx when running in dev mode

Open igordanchenko opened this issue 2 years ago • 3 comments

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

  1. Open https://codesandbox.io/p/sandbox/youthful-lalande-hdhslk sandbox
  2. Open dev tools Console tab
  3. Click the "Non-existent page" link on the homepage
  4. Observe the following error in the console:

Warning: Prop dangerouslySetInnerHTML did 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

igordanchenko avatar Jul 24 '23 12:07 igordanchenko

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.

ghost avatar Oct 06 '23 14:10 ghost

Same here, only <script> react tags with async attr would load

salikn avatar Jun 06 '24 23:06 salikn

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.

nextjs-bot avatar Dec 03 '25 23:12 nextjs-bot

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!

nextjs-bot avatar Dec 12 '25 23:12 nextjs-bot