fix: avoid infinite loops in crawlCSS (#1956)

This commit is contained in:
Nate Moore 2021-11-22 07:47:14 -06:00 committed by GitHub
parent 902405f4a3
commit 8775730eb9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix CSS scanning bug that could lead to infinite loops

View file

@ -18,6 +18,9 @@ export function getStylesForURL(filePath: URL, viteServer: vite.ViteDevServer):
function crawlCSS(entryModule: string, scanned = new Set<string>()) {
const moduleName = idToModuleMap.get(entryModule);
if (!moduleName) return;
if (!moduleName.id) return;
// mark the entrypoint as scanned to avoid an infinite loop
scanned.add(moduleName.id)
for (const importedModule of moduleName.importedModules) {
if (!importedModule.id || scanned.has(importedModule.id)) continue;
const ext = path.extname(importedModule.id.toLowerCase());