breaking: replace EnvVarConfig.static with EnvVarConfig.availability#16267
Conversation
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.
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/c6022386a403cfff1ed80fcf6b4915a0c8293d41Open in |
🦋 Changeset detectedLatest commit: c602238 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
| 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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
No - this is probably misphrased, it should be "Use this when the value is available both at build time and run time".
|
the options are a bit hard to grok. For example, What about 2 options:
If |
|
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. |
|
Then i think its just a matter of documentation. |
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
|
I opened a backward compatible fix for the site too so that previews will work sveltejs/svelte.dev#2089 |
The
static: booleanproperty on environment variable configs has been replaced byavailability, which has three possible values:'dynamic'(default, equivalent to the oldstatic: false) — the value is read at run time and also validated at build time'inline'(equivalent to the oldstatic: 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 thebuilding ? v.optional(...) : ...workaround for secrets and other variables that aren't set during the build.To migrate, replace
static: truewithavailability: 'inline'andstatic: falsewithavailability: 'dynamic'. Variables that previously used thebuildingworkaround can now useavailability: 'runtime'instead.closes #16195