Skip to content
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

'$env/dynamic/public' variables don't get loaded if ssr = false. #9275

Closed
ottomated opened this issue Mar 2, 2023 · 1 comment · Fixed by #9352
Closed

'$env/dynamic/public' variables don't get loaded if ssr = false. #9275

ottomated opened this issue Mar 2, 2023 · 1 comment · Fixed by #9352
Labels
bug Something isn't working
Milestone

Comments

@ottomated
Copy link
Contributor

Describe the bug

If you use '$env/dynamic/public' to import variables from process.env when export const ssr = false;, but prerendering is not explicitly disabled, the variables won't be sent to the client.

This is (I assume) because the html file is prerendered at build time, and uses the build-time variables. At runtime, it doesn't update the html file with the new values of process.env.

This works if export const prerender = false is set.

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-9cnqal?file=src/lib/Vars.svelte

Logs

No response

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 7.17.0 - /usr/local/bin/npm
  npmPackages:
    @sveltejs/adapter-node: ^1.2.0 => 1.2.0 
    @sveltejs/kit: ^1.5.0 => 1.9.2 
    svelte: ^3.54.0 => 3.55.1 
    vite: ^4.0.0 => 4.1.4

Severity

serious, but I can work around it

Additional Information

No response

@Rich-Harris
Copy link
Member

This is another manifestation of #8428. Perhaps we need to just disable that optimisation

@Rich-Harris Rich-Harris added this to the 2.0 milestone Mar 2, 2023
@Rich-Harris Rich-Harris added the bug Something isn't working label Mar 2, 2023
@Rich-Harris Rich-Harris mentioned this issue Mar 7, 2023
5 tasks
dummdidumm pushed a commit that referenced this issue Mar 8, 2023
reverts #8131
This reverts the optimisation wherein pages with ssr = false and no explicit prerender = false would automatically be prerendered, as it turns out to be unsafe.

fixes #9275
fixes #8428
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants