#(next-themes) Encountered a script tag while rendering React component.
1 messages · Page 1 of 1 (latest)
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:
-
The
notFound()rendering path is different: WhennotFound()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] -
React 19 has stricter script tag handling: There are known issues where inline
<script>tags rendered inside React components (including those injected by libraries likenext-themes) can cause warnings or errors, particularly during hydration or when rendering through error/not-found boundaries. [Scripts in Root Layout] -
The
notFound()function itself has known edge-case bugs: There are open issues aroundnotFound()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/scriptinstead of raw<script>tags where possible, as it handles script loading in a non-blocking, optimized way. [NEXTJS_USE_NEXT_SCRIPT] - If
next-themesinjects abeforeInteractive-style script, ensure it is placed insideapp/layout.jsx(the root layout), asbeforeInteractivescripts only work correctly in that context. [beforeInteractive outside Document]