From 52109674ddb52c7b9db214ee7b735d343fb9f4c2 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 13 Jul 2026 19:26:41 -0400 Subject: [PATCH] =?UTF-8?q?Revert=20"breaking:=20replace=20`EnvVarConfig.s?= =?UTF-8?q?tatic`=20with=20`EnvVarConfig.availabili=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit d5ffa2d16bae492c49cef826caf24da5c62b17a4. --- .changeset/env-availability.md | 5 -- .../70-environment-variables.md | 20 +++---- .../25-build-and-deploy/90-adapter-vercel.md | 2 +- .../test/apps/prerendered/src/env.ts | 2 +- .../adapter-static/test/apps/spa/src/env.ts | 2 +- packages/kit/src/core/adapt/builder.js | 5 +- packages/kit/src/core/env.js | 53 ++++++------------- packages/kit/src/exports/public.d.ts | 11 ++-- packages/kit/src/exports/vite/index.js | 4 +- packages/kit/test/apps/async/src/env.ts | 8 +-- packages/kit/test/apps/basics/src/env.ts | 14 ++--- packages/kit/test/apps/options-2/src/env.ts | 8 +-- packages/kit/test/apps/options/source/env.ts | 2 +- .../kit/test/prerendering/basics/src/env.ts | 4 +- packages/kit/types/index.d.ts | 11 ++-- 15 files changed, 57 insertions(+), 94 deletions(-) delete mode 100644 .changeset/env-availability.md diff --git a/.changeset/env-availability.md b/.changeset/env-availability.md deleted file mode 100644 index 0ac9bfbdf485..000000000000 --- a/.changeset/env-availability.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@sveltejs/kit': major ---- - -breaking: replace `EnvVarConfig.static` with `EnvVarConfig.availability` diff --git a/documentation/docs/20-core-concepts/70-environment-variables.md b/documentation/docs/20-core-concepts/70-environment-variables.md index 8e73d34e7606..d785468585c0 100644 --- a/documentation/docs/20-core-concepts/70-environment-variables.md +++ b/documentation/docs/20-core-concepts/70-environment-variables.md @@ -121,31 +121,27 @@ export const variables = defineEnvVars({ }); ``` -If a value is invalid, the app will fail to start (or build). If the variable is only available at run time (for example a secret that isn't set during the build), use `availability: 'runtime'` so that it is only validated when the app starts: +If a value is invalid, the app will fail to start (or build). To opt out of one or the other, use [`building`]($app-env#building) from `$app/env` along with a validator that accepts an optional value: ```ts /// file: src/env.ts import { defineEnvVars } from '@sveltejs/kit/hooks'; ++++import { building } from '$app/env'+++ import * as v from 'valibot'; export const variables = defineEnvVars({ SECRET: { - // required when the app starts, but not validated during the build - +++availability: 'runtime',+++ - schema: v.string() + // optional when building but required when starting the app + +++schema: building ? v.optional(v.string()) : v.string()+++ } }); ``` You can use validators to make values optional, or transform them (such as turning a string into a boolean, or parsing JSON) — see your validation library's documentation to learn how. -### Availability +### Static variables -The `availability` property controls when a variable's value is available, and therefore when it is validated. It has three possible values: - -- `'dynamic'` (default) — the value is validated and used during runtime and build time. -- `'inline'` — the value is inlined into your application code at build time, enabling optimisations like dead-code elimination. It is validated at build time. -- `'runtime'` — the value is validated and used during runtime only. The value is `undefined` during the build, so the variable is typed as `T | undefined`. +By default, variables are dynamic. If a variable is configured with `static: true`, it will be inlined into your application code, enabling optimisations like dead-code elimination: ```ts /// file: src/env.ts @@ -155,7 +151,7 @@ import * as v from 'valibot'; export const variables = defineEnvVars({ SHOW_DEBUG_OVERLAY: { public: true, - +++availability: 'inline',+++ + +++static: true,+++ // coerce to true/false schema: v.pipe( @@ -166,7 +162,7 @@ export const variables = defineEnvVars({ }); ``` -Because this variable is `inline`, the `` component shown here will be excluded from the JavaScript bundle unless `SHOW_DEBUG_OVERLAY` is truthy: +Because this variable is `static`, the `` component shown here will be excluded from the JavaScript bundle unless `SHOW_DEBUG_OVERLAY` is truthy: ```svelte