Conversation
🦋 Changeset detectedLatest commit: 5fd71e7 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 |
| const cssDeps: CompileCssResult['dependencies'][] = []; | ||
| const cssPartialCompileResults: PartialCompileCssResult[] = []; |
There was a problem hiding this comment.
Note: I refactored this from string[][] to { ... dependencies: string[] }[] because I needed to keep an extra isGlobal metadata whenever preprocessing is called.
| import '../components/One.astro'; | ||
| import '../components/Two.astro'; | ||
| await import('../components/Three.astro'); | ||
| await import('../components/Three.js'); |
There was a problem hiding this comment.
This PR caused this test to fail because the Three.astro component was imported but it's never used, hence the scoped styles in Three.astro weren't injected. Previously it was testing if the scoped styles were injected which I don't think it's quite right.
This test comes from #6176, so to stay true to what it's testing, I changed it to a .js file so that the CSS is no longer scoped.
e112e38 to
758663f
Compare
|
!preview treeshake-scoped-css |
|
Snapshots have been released for the following packages:
Publish LogBuild Log |
Changes
Unused scoped styles from Astro components are removed by checking if the main Astro module (that owns the scoped styles) is also removed/treeshaken. The PR copies some code from vitejs/vite#16058 to fix this at the meantime.
There's currently a tradeoff with this approach (vitejs/vite#16058 (comment)), but it should be better than before, and also it could be better.
Testing
Added a test. Also tested on a starlight project.
Docs
n/a. internal improvement