-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
When setting prerender to auto, $env/dynamic/public contains build-time environment variables #10737
Comments
This is the correct behaviour. The
https://kit.svelte.dev/docs/page-options#prerender Admittedly, we can produce a dev time warning for this that could make it clearer. |
Do you think this is a good behavior to keep ? I understand the logic from the point of view of the framework developer, but I doubt there is any case in which the application developer would want that. In my opinion, the correct behavior would be not to prerender pages that depend of runtime environment variables, instead of prerendering with incorrect (and potentially confidential) values for the variables. If the documentation says the values will be populated with runtime env variables, using build-time env variables instead is clearly a bug to me, whatever the situation. |
Hello guys, I would like to contribute on this one |
Perhaps we can throw an error if a page is being prerendered with the runtime environment variables module? This would ensure expectations are aligned (that the env data will be static).
Please feel free to submit a PR @baterson |
@lovasoa @s3812497 Could you give me a hint on that please I checked
But I couldn't find a convenient way to find out if module is using dynamic env variables, rather the reading it's file body. But during visit files are compiled already so I can't check whether it was an import from $env/dynamic/
I also checked kit/packages/kit/src/exports/vite/index.js Line 763 in 6bfcff2
|
@baterson I haven't fleshed this out but maybe a check for
|
… environment variables (sveltejs#10737)
It works, thanks! This is a good place to throw the Error. I'll open a PR after fixing falling tests |
I'm not sure if we should throw an error in this case. Runtime variables can also be added at built time, for example you could set a node env variable in your Vercel project dashboard which is used at build time. So while yes, in some cases it's a mistake, it's also needed in other cases - so we can't just throw an error. |
@dummdidumm @s3812497 Maybe show a Warning with the same message, instead of throwing the Error? |
@s3812497 I've opened a PR. Haven't found a good place to add a test though |
closed as duplicate of #10008 Did a bit of digging and found this older issue. I think just providing a warning might not be the solution we want. |
Describe the bug
$env/dynamic/public
is supposed to contain the environment variables set at runtime.However, when setting
export const prerender = 'auto'
, it contains static build-time environment variable values instead.Reproduction
src/routes/+page.js
src/routes/+page.svelte
build & run
Logs
No response
System Info
Severity
serious, but I can work around it
Additional Information
No response
The text was updated successfully, but these errors were encountered: