Website template: "Encountered a script tag" error on 404 pages in development
I maintainer di solito rispondono entro 1 giorno
@peteruithoven ci sta già lavorando.
Dal 13/11/2026.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- Mezza giornata
- Idoneità per principianti
- 25/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- nextjs, react, typescript
- Ambito
- frontend
Direzione di ricerca
The error comes from src/providers/Theme/InitTheme/index.tsx, which renders the theme script via next/script in the root layout; the ThemeProvider sets data-theme in an effect. Reproduce by visiting a non-existent route in the website template in dev and checking the browser console. Done means no 'Encountered a script tag' error on not-found pages while the theme still applies. Open PR #19580 already targets this, so check it before starting.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the Bug
In the website template, visiting any page that doesn't exist (which calls notFound()) logs this error in the browser console during development:
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).
Regular pages don't have this error.
The error comes from src/providers/Theme/InitTheme/index.tsx, which renders the theme script with next/script and strategy="beforeInteractive" in the root layout. On a notFound() page, Next.js renders the root layout on the client instead of hydrating server-rendered HTML. React then encounters the <script> during a client render, where it never executes, and logs the error.
The theme is still applied on those pages, because ThemeProvider also sets data-theme in an effect, so the script isn't needed in that case.
A possible fix is to render a plain <script> only when the component is server-rendered or hydrated, and render nothing during a fresh client render. For example, use useSyncExternalStore with a server snapshot of true and a client snapshot of false. I'm using this in my project and I'm happy to open a PR if that approach is acceptable.
ecommerce and with-vercel-website use the same InitTheme component.
Link to the code that reproduces this issue
https://github.com/peteruithoven/payload-website-404-issue
Reproduction Steps
The linked repo is an unmodified website template, created with pnpx create-payload-app@latest -t website (SQLite, Payload 3.93.0).
- Clone the repo and run
pnpm install cp .env.example .env, then setDATABASE_URL=file:./payload-website-404-issue.dbandPAYLOAD_SECRETto any stringpnpm dev- Open http://localhost:3000/this-page-does-not-exist
- Open the browser console: the "Encountered a script tag while rendering React component" error is logged.
- Open http://localhost:3000/ for comparison: no error.
No seeding is needed; it reproduces with an empty database.
Which area(s) are affected?
area: templates
Environment Info
Payload: 3.93.0
Next.js: 16.4.1
React: 19.2.9
Node.js: 24.22.3
- Lingua principale
- TypeScript
- Stelle
- 45.8k
- Fork
- 4.4k
- Merge medio
- 2g 16h
- PR unite (30g)
- 251
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di payloadcms/payload
-
db-d1-sqlite: upsert is aliased to updateOne, so payload.kv.set never inserts new keysForse già presa @pcbeingused333 l’ha presa 1 giorno fa. ApertaBug db: d1-sqlite Payload OSS
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
payloadcms/payload#19766 ·
I maintainer di solito rispondono entro 1 giorno
-
Document bar (.doc-controls__content) overflows a 375 px viewport, clips "Created" and fails axe scrollable-region-focusableForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertaarea: ui Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
payloadcms/payload#19690 ·
I maintainer di solito rispondono entro 1 giorno
-
[v4] Blocks thumbnails croped 3:2Forse già presa @samiarif02 l’ha presa 2 giorni fa. Apertaarea: ui Bug Payload OSS status: needs-triage v3
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
payloadcms/payload#19609 ·
I maintainer di solito rispondono entro 1 giorno
-
Scheduled publish jobs are not deleted when their document is deleted (string id in the job, raw id in the cleanup)Forse già presa @volodymyrshk l’ha presa 10 giorni fa. Apertaarea: core Bug db: sqlite
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
payloadcms/payload#19448 ·
I maintainer di solito rispondono entro 1 giorno
-
plugin-multi-tenant: `isGlobal` collections redirect tenant-scoped users to `/admin` since 3.93.0 (GlobalViewRedirect prop-name mismatch)Forse già presa @JarrodMFlesch l’ha presa 11 giorni fa. ApertaBug plugin: multi-tenant
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
payloadcms/payload#19420 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di payloadcms/payload
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
milind-soni/OpenMausBot#6730 ·
I maintainer di solito rispondono entro 1 giorno
-
`@angular/[email protected]` depends on vulnerable Vite 7.3.7 - GHSA-p4f5-76q4-ffq7 (Critical RCE)Apertaarea: @angular/build
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
angular/angular-cli#34764 ·
I maintainer di solito rispondono entro 1 giorno
-
status/need-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
google-gemini/gemini-cli#30384 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
P2
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno
-
area:image documentation good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno