-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
breaking: serve public env dynamically, prevent use of dynamic env va…
…rs during prerendering (#11277) * create _env.js dynamic module * tidy up * tidy up * allow %sveltekit.env.PUBLIC_FOO% to bypass proxy * add config option * update test * docs * apply same restriction to dynamic/private * separate comments * drive-by: partially fix message * tweak * update test * add test * migration notes * preload _env.js when appropriate * fix adapter-static tests * expose generateEnvModule method for adapter-static * check * windows * wow i really hate windows * bump adapter-static peer dependency * remove obsolete comment * changeset * doh * bump adapter-static as part of migration * update migration docs * reuse appDir instead of polluting everything * regenerate types --------- Co-authored-by: Rich Harris <[email protected]>
- Loading branch information
1 parent
4dc6aec
commit 9439190
Showing
38 changed files
with
235 additions
and
66 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sveltejs/kit': major | ||
--- | ||
|
||
breaking: prevent use of dynamic env vars during prerendering, serve env vars dynamically |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sveltejs/adapter-static': major | ||
--- | ||
|
||
breaking: update SvelteKit peer dependency to version 2 |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,6 @@ | |
"vite": "^5.0.8" | ||
}, | ||
"peerDependencies": { | ||
"@sveltejs/kit": "^1.5.0 || ^2.0.0" | ||
"@sveltejs/kit": "^2.0.0" | ||
} | ||
} |
8 changes: 7 additions & 1 deletion
8
packages/adapter-static/test/apps/prerendered/src/routes/public-env/+page.svelte
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
<script> | ||
import { browser } from '$app/environment'; | ||
import { PUBLIC_ANSWER } from '$env/static/public'; | ||
import { env } from '$env/dynamic/public'; | ||
</script> | ||
|
||
<h1>The answer is {env.PUBLIC_ANSWER}</h1> | ||
<h1>The answer is {PUBLIC_ANSWER}</h1> | ||
|
||
{#if browser} | ||
<h2>The dynamic answer is {env.PUBLIC_ANSWER}</h2> | ||
{/if} |
This file contains 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
4 changes: 2 additions & 2 deletions
4
packages/adapter-static/test/apps/spa/src/routes/fallback/[...rest]/+page.svelte
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<script> | ||
import { env } from '$env/dynamic/public'; | ||
import { PUBLIC_VALUE } from '$env/static/public'; | ||
</script> | ||
|
||
<h1>the fallback page was rendered</h1> | ||
|
||
<b>{env.PUBLIC_VALUE}</b> | ||
<b>{PUBLIC_VALUE}</b> |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const env_static_private = '\0virtual:$env/static/private'; | ||
export const env_static_public = '\0virtual:$env/static/public'; | ||
export const env_dynamic_private = '\0virtual:$env/dynamic/private'; | ||
export const env_dynamic_public = '\0virtual:$env/dynamic/public'; | ||
export const service_worker = '\0virtual:$service-worker'; | ||
export const sveltekit_paths = '\0virtual:__sveltekit/paths'; | ||
export const sveltekit_environment = '\0virtual:__sveltekit/environment'; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { public_env } from '../shared-server.js'; | ||
|
||
/** @type {string} */ | ||
let body; | ||
|
||
/** @type {string} */ | ||
let etag; | ||
|
||
/** @type {Headers} */ | ||
let headers; | ||
|
||
/** | ||
* @param {Request} request | ||
* @returns {Response} | ||
*/ | ||
export function get_public_env(request) { | ||
body ??= `export const env=${JSON.stringify(public_env)}`; | ||
etag ??= `W/${Date.now()}`; | ||
headers ??= new Headers({ | ||
'content-type': 'application/javascript; charset=utf-8', | ||
etag | ||
}); | ||
|
||
if (request.headers.get('if-none-match') === etag) { | ||
return new Response(undefined, { status: 304, headers }); | ||
} | ||
|
||
return new Response(body, { headers }); | ||
} |
This file contains 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
Oops, something went wrong.