-
-
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
Omit env
from server renders if $env/dynamic/public
isn't used
#8946
Comments
What would be the best way to check whether |
In dev we'd just assume it was always used, because we can't really know. At build time we can inspect the module graph to know which modules are imported, though drawing the rest of the owl is finicky and I always struggle with it a bit. We're doing something similar already to ensure that you don't accidentally import kit/packages/kit/src/exports/vite/index.js Lines 370 to 397 in 98226de
We can probably reuse the kit/packages/kit/src/exports/vite/index.js Line 630 in 98226de
Because the plugin gets reinstantiated for the client build, I think we'd need to store that list of modules in a variable the same way we store kit/packages/kit/src/exports/vite/index.js Lines 661 to 669 in 98226de
so that render.js can omit the script block when it generates HTML. All of which sounds terribly convoluted — we're building a server so that we can analyse it in order to create an optimised client build, which we then analyse so that we can optimise the server — but I think it'll work. |
I'm looking into #8997, and we might actually not want to do this. Am investigating option 2, wherein requests for I'm not sure if this the best approach, since it won't work in cases where |
Reverse ferret: turns out we can't do the |
Is this issue solved in SvelteKit2 @Rich-Harris |
Describe the problem
Every public environment variable is made available to client-side code via
$env/dynamic/public
in the init block:But many apps don't actually use
$env/dynamic/public
, they use$env/static/public
instead (which in general is preferred).Describe the proposed solution
Detect cases where
$env/dynamic/public
is not imported by client-side code, and omit public env vars from the init block.Alternatives considered
No response
Importance
nice to have
Additional Information
No response
The text was updated successfully, but these errors were encountered: