fix(layout): render PublicEnvScript as plain inline <script>

next-runtime-env's <PublicEnvScript /> uses next/script beforeInteractive
internally. On Next.js error-page shells (<html id="__next_error__">),
beforeInteractive is not honored — the env script is serialized into the
RSC stream instead of being hoisted as a real <script> in <head>, so it
runs after client chunks evaluate. Any module that calls getBaseUrl()
at module-eval time (e.g. lib/auth/auth-client.ts) then crashes because
window['__ENV'] is still undefined.

disableNextScript renders a plain inline <script> in <head> that the
browser executes synchronously during HTML parse on every render path,
including error pages. Fixes "Application error: a client-side exception"
on 404 routes like /models/anthropic/xxx and /integrations/rand.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Waleed Latif
2026-04-21 11:45:15 -07:00
parent 8ad41a2e2b
commit 55f55ff900

View File

@@ -239,7 +239,7 @@ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
</>
)}
<PublicEnvScript />
<PublicEnvScript disableNextScript />
</head>
<body className={`${season.variable} font-season`} suppressHydrationWarning>
{/* Google Tag Manager (noscript) — hosted only */}