Error Type Console Error Error Message Encountered a script tag while rendering React…
- User
Error Type
Console Error
Error Message
Encountered a script tag while rendering React component. Scripts inside React components are never executed when rendering on the client. Consider using template tag instead (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template).
codeat script (unknown:0:0) at RootLayout (app/layout.tsx:25:7)Code Frame
23 | 24 |
25 | <script | ^ 26 | dangerouslySetInnerHTML={{ 27 | __html: ` 28 | try {
Next.js version: 16.2.4 (Turbopack)
- Assistant
This is a Next.js 16 / React 19 behavior — inline
<script>tags rendered directly in a component's JSX are no longer executed. The fix is to use Next'sScriptcomponent with abeforeInteractivestrategy. - Assistant
Let me check the
JsonLdScriptscomponent since it may have the same issue: - Assistant
The
JsonLdScriptscomponent uses the same bare<script>pattern, so it will hit the same React 19 warning. Let me fix it too by converting tonext/script: - Assistant
Let me verify the final state of both files:
- Assistant
Let me check for any other bare
<script>tags in the project that could trigger the same warning: - Assistant
next/scriptwithbeforeInteractiverequires a uniqueidper script. The JSON-LD wrappers don't set one — let me add ids: - Assistant
The
BreadcrumbJsonLdalso usesJsonLdScriptwithout an id. Let me check and fix it: - Assistant
Let me verify there are no type errors with a quick typecheck:
- Assistant
next/scriptuses a default export. Let me fix both imports: - Assistant
Typecheck passes. Here's what I changed and why:
Root cause
Next.js 16 / React 19 no longer executes (or even tolerates) bare
<script>tags rendered directly in component JSX — React warnsScripts inside React components are never executed when rendering on the client. YourRootLayouthead had one inline<script>for the theme-color bootstrap, andJsonLdScriptshad several more for structured data.Fix
Switched both to Next's
Scriptcomponent withstrategy="beforeInteractive", which is the supported way to inject scripts into the initial HTML in Next 16:app/layout.tsx— wrapped the theme-color bootstrap in<Script id="theme-color-script" strategy="beforeInteractive" ... />.seo/json-ld.tsx— replaced the bare<script>inJsonLdScriptwith<Script>and added a uniqueidto each call (json-ld-website,json-ld-software-source-code, , ), since / require an .