-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
🐛 BUG: CSS generated by Astro.glob
is included on all pages
#3816
Comments
Astro.glob
Astro.glob
is included on all pages
So I looked into this during #3932. Seems like this is not related to HMR, but is the result of how we're crawling the module graph to discover CSS during dev. This is probably a bigger issue to tackle. |
thank you for looking into this :) any plans to introduce globs without rendering markdown (just frontmatter) though? :) |
@natemoo-re anything that we can do here before v1.0 next week? |
@FredKSchott and I discussed this with the rest of the team. Given how close we are to v1.0.0, we won't be able to explore this feature in time. However, the ability to glob files while not importing any CSS (as @JLarky suggested) sounds extremely useful and is something we'd like to tackle in the future. |
@natemoo-re Is this issue available to work on? |
We're beginning to plan our post-v1.0 roadmap! |
Relabelled this as a p2, not because it's not important, it's very important. So important that @bholmesdev has been spending weeks working on a solution for this. Relabelled because p4 is for documented behavior bugs and we do not document that Astro.glob usage will not bleed styles. |
Indeed! @JLarky I suggest checking out the Content Schemas RFC for an early look, particularly the "Render Content" piece of the proposal. Open for feedback on the user-facing API 👍 |
@matthewp What is the workaround for this issue? |
@Enteleform Sadly no workaround today. This is a fundamental issue with how Vite handles CSS injection by default, and requires Astro core changes to override. |
@bholmesdev Oh, I thought the |
@Enteleform Ah, didn't notice that p2 flag. I agree that's misleading, apologies! |
I was facing the same issue. I resolved it by changing my astro version to |
Content Collections from Astro 2.0 don't fix this on their own. Content collections are not a replacement for This bug still persists and makes Astro really unusable for larger projects. Flagging this as a "minor bug" is ridiculous. This will break styling and performance on any pages that use |
Thanks for sharing @ChingChang9! Yes, content collections are the intended fix for script and style bleed when using MDX files. We will unfortunately be closing this issue as a "will not fix" for If you have a compelling use case where content collections cannot be used, and style bleed is a critical issue, please open a discussion on our roadmap. Thanks everyone! |
@bholmesdev Did you want to say that "Content collections + manual routing" are the intended fix? As I said in my last post, Content collections alone do not fix this. |
@pReya yes, this is the intended flow when reusing your content in multiple places. i.e. as manual routes, as a collection import for a landing page, as an RSS feed, etc. |
What version of
astro
are you using?1.0.0-beta.63
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
pnpm
What operating system are you using?
Mac
Describe the Bug
becase
Astro.glob('../pages/posts/*.md')
will render those markdown files it will also include css files used in them. The issue I noticed is that HRM logic will not unload that css files until you restart youastro dev
.Steps to reproduce:
astro-hmr-css-bug
branch from https://github.com/JLarky/jlarky-blog/tree/astro-hmr-css-bugastro dev
* {color: red}
css in themastro dev
You can do the same with https://stackblitz.com/github/JLarky/jlarky-blog/tree/astro-hmr-css-bug but instead of restarting
astro dev
you would do a full page reload of stackblitz appPossible solutions:
Astro.globMetadataOnly
that will skip markdown rendering 🤪Astro.glob
but if you navigate away from this page css gets properly unloadedI first saw this issue here: https://youtu.be/EU1MLQMUeXw?t=3490 at 58:58 you can see that I switch to another page but
color: red
is still applied.Link to Minimal Reproducible Example
https://stackblitz.com/github/JLarky/jlarky-blog/tree/astro-hmr-css-bug
Participation
The text was updated successfully, but these errors were encountered: