#(next-themes) Encountered a script tag while rendering React component.

1 messages · Page 1 of 1 (latest)

median saffronBOT
#

Hi @dapper oak. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

The knowledge sources do not contain enough information to directly address the specific error you're encountering with next-themes and its script tag injection conflicting with React 19's script tag handling during notFound() rendering.

However, based on the knowledge sources, I can share some relevant context:

  1. The notFound() rendering path is different: When notFound() is triggered, Next.js follows a different rendering path — the layout is streamed in separately, and inline scripts from layouts can sometimes fail to execute or cause conflicts in this context. [Inline script issue]

  2. React 19 has stricter script tag handling: There are known issues where inline <script> tags rendered inside React components (including those injected by libraries like next-themes) can cause warnings or errors, particularly during hydration or when rendering through error/not-found boundaries. [Scripts in Root Layout]

  3. The notFound() function itself has known edge-case bugs: There are open issues around notFound() causing unexpected crashes or rendering failures in dynamic routes, especially with certain layout configurations. [notFound crash issue]

What you can try (based on what the knowledge sources suggest about script handling):

#
  • Consider using next/script instead of raw <script> tags where possible, as it handles script loading in a non-blocking, optimized way. [NEXTJS_USE_NEXT_SCRIPT]
  • If next-themes injects a beforeInteractive-style script, ensure it is placed inside app/layout.jsx (the root layout), as beforeInteractive scripts only work correctly in that context. [beforeInteractive outside Document]

For the specific next-themes + React 19 + notFound() interaction, I'd recommend checking the next-themes GitHub repository for open issues, as this appears to be a library-level compatibility concern that isn't covered in the available knowledge sources.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: