-
-
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
CSS bundling issue with lazy components #11404
Comments
This is an architectural issue with how Astro bundling works. All CSS imported on a page gets bundled together. There isn't a way to dynamically add CSS the way that you'd want it to due to streaming. |
but the components explicitly behind a lazy boundary shouldn't have their CSS loaded as it would already be in that chunk. |
Does your example show duplication occuring? |
|
the |
confirmed, you can build and preview the example i have added, the css is being duplicated in it |
Any updated on this? |
I think this vite PR will help to fix this issue |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
When we have a lazy loaded component, its css is still getting bundled into the page's css
Consider the following component tree: (in stackblitz example)
Now what happens is:
/
page it contains css for all three components, even if the bundle forLazyLoaded.jsx
is not yet loaded.LazyLoaded
component, the js bundle for it is loaded and also a css file is loaded which contains css loaded in that component. This css was already in the page so is a waste request and duplicates styles.What's the expected result?
When we load the
/
page, i would expectindex.astro
&Loader.jsx
LazyLoaded.jsx
should be loaded when js file for it is requestedMy initial goal for doing all this is:
I want to utilize
inlineStylesheets: always
to have all styles inlined on the page except for the components which are lazy loaded (modals etc).Before someone shouts this is bad, this is to optimize for fp/fcp & cls. Our pages render from cached data & avg. page size is less than 50kb with styles inlined so is okay to do. This is what we were already doing with nextjs, dont wanna loose on this critial css optimization in migrating to astro.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/withastro-astro-jsmmdp
Participation
The text was updated successfully, but these errors were encountered: