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

avoid double import of $env/dynamic/[mode] modules #5955

Merged
merged 4 commits into from
Aug 17, 2022
Merged

Conversation

Rich-Harris
Copy link
Member

Attempt to fix #5941. No test because the bug doesn't happen inside the workspace

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

@changeset-bot
Copy link

changeset-bot bot commented Aug 16, 2022

🦋 Changeset detected

Latest commit: af28ffc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@benmccann
Copy link
Member

Will this prevent the user from being able to change the env files after server startup?

@Rich-Harris
Copy link
Member Author

Changing .env will cause the dev server to be restarted

Copy link
Member

@benmccann benmccann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. although I haven't fully followed what's happening and why this fixes things. @bluwy and @dominikg might be understanding the situation more closely

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benmccann it looks like the issue is that we're slightly tapping into Vite's internals to load env-private.js and env-public.js, where if Vite controls the entire import analysis flow, it would usually load them as /node_modules/@sveltejs/kit/src/runtime/env-private.js. Only imports outside of root would (usually?) use /@fs, which this PR changes to emulate this.

Ideally we would put these runtime files in pkg.exports, so we can ssrLoadModule them directly without resolving the path ourselves, but @Rich-Harris brought up that we want to keep this private API and intellisense-wise.

I think the solution now is fine, but if more issues appear later, it could be worth investigating a safer way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynamic Public Environment Variables are undefined in +server.ts endpoints
3 participants