-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Vite's define
dev-mode timing issues in .astro
files
#11874
Comments
Hi @AriPerkkio, what is happening here is that because you are using This is intended behavior, you should only rely on the Also note that the |
The So basically: <script>
console.log("This is will cause crash", __MY_DEFINE__);
</script>
<script>
setTimeout(() => console.log("This is defined", __MY_DEFINE__), 1_000);
</script> So is it safe to assume that when accessing variables set by Vite's |
It looks like it's because we injected the We could maybe go back and fix this in v4 when |
Thanks for the details, that makes sense. Having |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
In development mode, it's possible that values defined in Vite's
define
are not present in.astro
files immediately. Note that there is a difference in Vite howdefine
works when comparing dev and prod modes - prod uses static replacements, dev adds them toglobalThis
on runtime.Maybe Astro is loading
.astro
files before Vite defines values fromdefine
? Is Astro now too fast?What's the expected result?
Values defined in Vite's
define
should always be present, even in.astro
files. Thedefine
option should provide similar results in dev as it does in prod.Link to Minimal Reproducible Example
https://stackblitz.com/~/edit/github-5kyhn9?file=src%2Fpages%2Findex.astro
Participation
The text was updated successfully, but these errors were encountered: