mirror of
https://github.com/withastro/astro.git
synced 2025-03-10 23:01:26 -05:00
Skip crawling into CSS requests when crawling module graph (#10911)
This commit is contained in:
parent
05d58eff07
commit
a86dc9d269
2 changed files with 14 additions and 8 deletions
5
.changeset/afraid-mirrors-tease.md
Normal file
5
.changeset/afraid-mirrors-tease.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"astro": patch
|
||||
---
|
||||
|
||||
Skips adding CSS dependencies of CSS Vite modules as style tags in the HTML
|
|
@ -41,7 +41,15 @@ export async function* crawlGraph(
|
|||
}
|
||||
if (id === entry.id) {
|
||||
scanned.add(id);
|
||||
const entryIsStyle = isCSSRequest(id);
|
||||
|
||||
// CSS requests `importedModules` are usually from `@import`, but we don't really need
|
||||
// to crawl into those as the `@import` code are already inlined into this `id`.
|
||||
// If CSS requests `importedModules` contain non-CSS files, e.g. Tailwind might add HMR
|
||||
// dependencies as `importedModules`, we should also skip them as they aren't really
|
||||
// imported. Without this, every hoisted script in the project is added to every page!
|
||||
if (isCSSRequest(id)) {
|
||||
continue
|
||||
}
|
||||
|
||||
for (const importedModule of entry.importedModules) {
|
||||
if (!importedModule.id) continue;
|
||||
|
@ -54,13 +62,6 @@ export async function* crawlGraph(
|
|||
// NOTE: Cannot use `new URL()` here because not all IDs will be valid paths.
|
||||
// For example, `virtual:image-loader` if you don't have the plugin installed.
|
||||
const importedModulePathname = importedModule.id.replace(STRIP_QUERY_PARAMS_REGEX, '');
|
||||
// If the entry is a style, skip any modules that are not also styles.
|
||||
// Tools like Tailwind might add HMR dependencies as `importedModules`
|
||||
// but we should skip them--they aren't really imported. Without this,
|
||||
// every hoisted script in the project is added to every page!
|
||||
if (entryIsStyle && !isCSSRequest(importedModulePathname)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const isFileTypeNeedingSSR = fileExtensionsToSSR.has(npath.extname(importedModulePathname));
|
||||
// A propagation stopping point is a module with the ?astroPropagatedAssets flag.
|
||||
|
|
Loading…
Add table
Reference in a new issue