-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
breaking: serve public env dynamically, prevent use of dynamic env vars during prerendering #11277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
ceb7503
create _env.js dynamic module
Rich-Harris bb540aa
tidy up
Rich-Harris ced5f32
tidy up
Rich-Harris 18c0a9d
allow %sveltekit.env.PUBLIC_FOO% to bypass proxy
Rich-Harris c921db8
add config option
Rich-Harris f71120f
update test
Rich-Harris 2f91cd6
docs
Rich-Harris 20a2ca1
apply same restriction to dynamic/private
Rich-Harris ca45fa7
separate comments
Rich-Harris e36107f
drive-by: partially fix message
Rich-Harris 48b7512
tweak
Rich-Harris d2ff6af
update test
Rich-Harris a132100
add test
Rich-Harris c129696
migration notes
Rich-Harris 0f15ede
preload _env.js when appropriate
Rich-Harris 050e113
fix adapter-static tests
Rich-Harris c438191
expose generateEnvModule method for adapter-static
Rich-Harris c336ee2
check
Rich-Harris 115bd19
windows
Rich-Harris 1197fcd
wow i really hate windows
Rich-Harris e5836a4
bump adapter-static peer dependency
Rich-Harris 6bc7b8e
remove obsolete comment
Rich-Harris 17fd0e0
changeset
Rich-Harris e87f14c
doh
Rich-Harris 27b7aad
bump adapter-static as part of migration
Rich-Harris 0337f6f
update migration docs
Rich-Harris 3a0be04
reuse appDir instead of polluting everything
Rich-Harris 400806a
merge
Rich-Harris d4f7ce2
regenerate types
Rich-Harris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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 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
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 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
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
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
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 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
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 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
4 changes: 2 additions & 2 deletions
4
packages/adapter-static/test/apps/spa/src/routes/fallback/[...rest]/+page.svelte
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
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 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
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
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
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
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
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
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
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
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
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 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
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 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.