Skip to content

breaking: replace EnvVarConfig.static with EnvVarConfig.availability#16267

Merged
dummdidumm merged 11 commits into
version-3from
env-availability
Jul 13, 2026
Merged

breaking: replace EnvVarConfig.static with EnvVarConfig.availability#16267
dummdidumm merged 11 commits into
version-3from
env-availability

Conversation

@dummdidumm

@dummdidumm dummdidumm commented Jul 7, 2026

Copy link
Copy Markdown
Member

The static: boolean property on environment variable configs has been replaced by availability, which has three possible values:

  • 'dynamic' (default, equivalent to the old static: false) — the value is read at run time and also validated at build time
  • 'inline' (equivalent to the old static: true) — the value is inlined at build time, enabling dead-code elimination
  • 'runtime' — the value is only available at run time and is not validated during the build, so the build succeeds even if the value is absent. This replaces the building ? v.optional(...) : ... workaround for secrets and other variables that aren't set during the build.

To migrate, replace static: true with availability: 'inline' and static: false with availability: 'dynamic'. Variables that previously used the building workaround can now use availability: 'runtime' instead.

closes #16195

The `static: boolean` property on environment variable configs has been replaced by `availability`, which has four possible values:

- `'dynamic'` (default, equivalent to the old `static: false`) — the value is read at run time and also validated at build time
- `'static'` (equivalent to the old `static: true`) — the value is inlined at build time, enabling dead-code elimination
- `'runtime'` — the value is only available at run time and is not validated during the build, so the build succeeds even if the value is absent. This replaces the `building ? v.optional(...) : ...` workaround for secrets and other variables that aren't set during the build.
- `'build'` — the value is only available during the build, validated at build time, but not accessible from `$app/env/*` at run time

To migrate, replace `static: true` with `availability: 'static'` and `static: false` with `availability: 'dynamic'`. Variables that previously used the `building` workaround can now use `availability: 'runtime'` instead.
@pkg-svelte-dev

pkg-svelte-dev Bot commented Jul 7, 2026

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from c602238:

pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/c6022386a403cfff1ed80fcf6b4915a0c8293d41

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/kit/pr/16267

@changeset-bot

changeset-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c602238

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dummdidumm
dummdidumm marked this pull request as draft July 7, 2026 21:32
@svelte-docs-bot

Copy link
Copy Markdown

Comment thread packages/kit/src/core/adapt/builder.js
Comment thread packages/kit/test/apps/options-2/test/env.test.js Outdated
Comment thread packages/kit/test/apps/options-2/test/env.test.js Outdated
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:
The `availability` property controls when a variable's value is available, and therefore when it is validated. It has four possible values:

- `'dynamic'` (default) — the value is read from the environment when the app starts, and is also validated at build time. Use this when the value is the same at build time and run time.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use this when the value is the same at build time and run time.

Shouldn't it be the other way around, use this when it is different?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No - this is probably misphrased, it should be "Use this when the value is available both at build time and run time".

@sacrosanctic

sacrosanctic commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

the options are a bit hard to grok. For example, runtime is also dynamic.

What about 2 options:

  • availability: runtime, buildtime, both (defaults to both)
  • inline: true, false (defaults to false)

inline here applies to build so it works with buildtime and both. We can just let it happen for runtime where it does nothing or disallow it with a discriminated union.

If buildtime is removed, the options could be runtime, both, both-static

@dummdidumm

Copy link
Copy Markdown
Member Author

These options are mutually exclusive. If something is inlined, it is always present (both at build time and runtime). So it doesn't make sense to split up into another option.

@sacrosanctic

Copy link
Copy Markdown
Contributor

Then i think its just a matter of documentation.

Comment thread documentation/docs/20-core-concepts/70-environment-variables.md Outdated
@dummdidumm
dummdidumm marked this pull request as ready for review July 10, 2026 12:12
Comment thread documentation/docs/20-core-concepts/70-environment-variables.md Outdated
Comment thread documentation/docs/20-core-concepts/70-environment-variables.md Outdated
Comment thread packages/kit/src/exports/public.d.ts Outdated
Comment thread packages/kit/types/index.d.ts Outdated
Comment thread packages/kit/src/core/env.js
dummdidumm and others added 2 commits July 10, 2026 22:39
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
@teemingc

Copy link
Copy Markdown
Member

I opened a backward compatible fix for the site too so that previews will work sveltejs/svelte.dev#2089

@dummdidumm
dummdidumm merged commit d5ffa2d into version-3 Jul 13, 2026
17 of 18 checks passed
@dummdidumm
dummdidumm deleted the env-availability branch July 13, 2026 20:26
Rich-Harris added a commit that referenced this pull request Jul 13, 2026
…ailability`" (#16335)

Reverts #16267 because there are still some outstanding
questions about the API, and we don't want to block #16282 on it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a more straightforward method of opting dynamic explicit environment variables out of build-time validation

3 participants