Next.js NEXT_PUBLIC_ env var ignores the value set at next start / docker run: inlined at build time, even in server components
Next.js 16.3.2 (Turbopack), macOS. Common in Docker: one image, different env per deploy.
Built with NEXT_PUBLIC_API_URL=https://build.example API_URL=https://build-secret.example next build, then ran NEXT_PUBLIC_API_URL=https://runtime.example API_URL=https://runtime-secret.example next start.
A dynamic server component (await connection()) rendering both printed: server pub=https://build.example secret=https://runtime-secret.example. So the NEXT_PUBLIC_ value is frozen at build time even on the server, while the unprefixed var is read at runtime.
The client chunk in .next/static/chunks contains the literal: pub=https://build.example secret=${t.default.env.API_URL}. The prefixed var is string-replaced; the unprefixed one is left as a lookup on a browser process shim, not your server env.
Cause: next build replaces every process.env.NEXT_PUBLIC_X with its build-time value in both server and client bundles.
Fix: rebuild per environment, or keep runtime config unprefixed, read it in a server component (or a route handler) and pass it to client components as props.