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

Improve env var handling in SSR #9637

Merged
merged 1 commit into from
Jan 9, 2024
Merged

Improve env var handling in SSR #9637

merged 1 commit into from
Jan 9, 2024

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Jan 8, 2024

Changes

Some env var replacement can be relayed to Vite to replace instead, which is more accurate as we're using plain string replacements. I'm currently working on improving Astro's env replacement too and notice this stop gap improvement.

Testing

Existing env vars tests should pass.

Docs

n/a. internal refactor.

Copy link

changeset-bot bot commented Jan 8, 2024

🦋 Changeset detected

Latest commit: c9e2cd9

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

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

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) pr: docs A PR that includes documentation for review labels Jan 8, 2024
Comment on lines -51 to -56
privateEnv.SITE = astroConfig.site ? JSON.stringify(astroConfig.site) : 'undefined';
privateEnv.SSR = JSON.stringify(true);
privateEnv.BASE_URL = astroConfig.base ? JSON.stringify(astroConfig.base) : 'undefined';
privateEnv.ASSETS_PREFIX = astroConfig.build.assetsPrefix
? JSON.stringify(astroConfig.build.assetsPrefix)
: 'undefined';
Copy link
Member Author

Choose a reason for hiding this comment

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

We don't need to re-specify these here as Vite will already handle them. If we specify them here, we'd do a plain string replacement instead, which is less accurate than Vite's implementation.

@@ -308,3 +308,7 @@ function isCommonNotAstro(dep: string): boolean {
)
);
}

function stringifyForDefine(value: string | undefined): string {
Copy link
Member

Choose a reason for hiding this comment

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

Should it be stringifyOrDefine?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is "For" since we're stringifying the value for the define config passed to Vite.

@bluwy bluwy merged commit 5cba637 into main Jan 9, 2024
13 checks passed
@bluwy bluwy deleted the simplify-env branch January 9, 2024 08:29
@astrobot-houston astrobot-houston mentioned this pull request Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) pr: docs A PR that includes documentation for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants