Open patheticGeek opened 4 months ago
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. or at the very least the CSS shouldn't be loaded twice & duplicated :thinking: that seems like a bug that css is added in both, the page & the lazy chunk
Does your example show duplication occuring?
~yes.~ checking the example once :thinking: it was for me
the .lazy-loaded
class appears in the page css (with any inlineStylesheets
value) and is also loaded in the css file which is loaded when LazyLoaded.jsx
's chunk is loaded
confirmed, you can build and preview the example i have added, the css is being duplicated in it it appears in the initial
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