docs: correct the browser envName() fallback (development, not production)#28
Merged
Conversation
…tion) Three doc pages and the __ENV_NAME__ JSDoc claimed that, without the envConfig() Vite plugin, envName() in browser code falls back to "production". That is only true on the server: in the browser readEnv() reads window.__env, never process.env, so a pure SPA sees neither NODE_ENV nor VITE_ENV and envName() falls through to its "development" fallback — silently shipping the dev config to every environment. Reframe the "Vite gotcha" / custom-modes framing accordingly: the plugin is required for any non-development browser build, not just custom modes like staging/qa. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
vlandoss-env-docs | 995ef13 | Commit Preview URL Branch Preview URL |
Jun 17 2026, 03:08 AM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Three docs pages and the
__ENV_NAME__JSDoc claimed that, without theenvConfig()Vite plugin,envName()in browser code falls back to"production". That is wrong — it's only true on the server.Why it's wrong
In the browser,
envName()'sreadEnv()reads onlywindow.__env(or the<EnvScript />tag) — neverprocess.envorimport.meta.env. So in a pure SPA, neitherNODE_ENVnorVITE_ENVis visible, and with no plugin (no__ENV_NAME__) every entry in the precedence chain is empty:envName()falls through to its"development"fallback — silently shipping the dev config to every environment — regardless of the--modeorVITE_ENVused at build time. Verified empirically:VITE_ENV=production vite buildwithout the plugin still resolvesdevelopmentin the browser;__ENV_NAME__is left as a bare identifier (nodefine), sobuildTimeEnvName()returnsundefined.This is exactly the trap it sounds like: a build that works locally (where
developmentis what you want) quietly mis-targets in production.Changes
concepts/env-name.mdx— fix the precedence note (item 2) and the "Vite gotcha" section.guides/custom-modes.mdx— fix the "The problem" framing.guides/spa-dynamic-import.mdx— fix theenvConfig()plugin rationale bullet.package/src/lib/const.ts— tighten the__ENV_NAME__JSDoc (shipped with the package), hence thepatchchangeset.The reframe throughout: the plugin is required for any non-development browser build, not just custom modes like
staging/qa. The examples were already correct (spa-vite-dynamicandspa-vite-pluginboth wireenvConfig()); only the prose was misleading.🤖 Generated with Claude Code