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

fix(i18n): use define to deliver config to virtual module #9838

Merged
merged 5 commits into from
Jan 29, 2024

Conversation

lilnasy
Copy link
Contributor

@lilnasy lilnasy commented Jan 26, 2024

Changes

  • Switches the approach used to deliver i18n config to the astro:i18n module.
  • The virtual module approach broke in mysterious ways.

Testing

Existing tests should pass.

Docs

Does not affect usage.

Copy link

changeset-bot bot commented Jan 26, 2024

🦋 Changeset detected

Latest commit: 288128f

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 the pkg: astro Related to the core `astro` package (scope) label Jan 26, 2024
Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

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

Not my favorite solution, but if it works, it works!

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Can we add a test? As far as I understood, there was a way to reproduce it

@lilnasy
Copy link
Contributor Author

lilnasy commented Jan 27, 2024

The error happens on dev startup, during some work being performed by a plugin called vite:dep-scan. It would be simpler if it happened on request. I'm not confident a test can catch but I'll take a look.

@lilnasy
Copy link
Contributor Author

lilnasy commented Jan 27, 2024

No luck.

The fact that a fetch request itself will succeed with expected html aside, the bug won't even happen in our monorepo. It seems to be one of these cases where vite is sensitive to whether astro is linked or copied to node_modules.

@ematipico
Copy link
Member

Thank you for taking the time to explain and double check.

@bluwy
Copy link
Member

bluwy commented Jan 27, 2024

Can you explain how this fixes the issue? Using import.meta.env this way may bloat the size if the user references import.meta.env itself in runtime.

EDIT: I missed your message that it happen in vite:dep-scan. I'm not sure how it hit that issue in the first place, but if we do want to use this trick, I think we should define something like __ASTRO_INTERNAL_I18n_CONFIG__ instead, so it's not prefixed with import.meta.env.*

@lilnasy
Copy link
Contributor Author

lilnasy commented Jan 27, 2024

AFAIK, it will not appear on import.meta.env. define only does a string replace, doesn't it?

@lilnasy
Copy link
Contributor Author

lilnasy commented Jan 27, 2024

I'm guessing astro-env-inject picks it up.

@lilnasy lilnasy changed the title fix(i18n): use import.meta.env to deliver config to virtual module fix(i18n): use define to deliver config to virtual module Jan 27, 2024
@bluwy
Copy link
Member

bluwy commented Jan 29, 2024

AFAIK, it will not appear on import.meta.env. define only does a string replace, doesn't it?

Vite would use import.meta.env.* in define: https://github.com/vitejs/vite/blob/f9c33add88e8edcd54316629724730d8049447f1/packages/vite/src/node/plugins/define.ts#L50-L53. The entire object may get inlined for import.meta.env as it represents an object of all the keys and values.

@lilnasy
Copy link
Contributor Author

lilnasy commented Jan 29, 2024

I didn't know that, thanks!

Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
@lilnasy lilnasy merged commit 0a06d87 into withastro:main Jan 29, 2024
13 checks passed
@astrobot-houston astrobot-houston mentioned this pull request Jan 29, 2024
@lilnasy lilnasy deleted the i18n-config-fix branch January 30, 2024 20:55
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)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants