0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00

fix: ensure SSR module is loaded before testing is CSS (#4621)

This commit is contained in:
Allan Chain 2022-09-06 20:25:26 +08:00 committed by GitHub
parent 63cd9d89e8
commit 0068afb876
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Ensure SSR module is loaded before testing if it's CSS in dev

View file

@ -18,11 +18,14 @@ export async function getStylesForURL(
for await (const importedModule of crawlGraph(viteServer, viteID(filePath), true)) {
const ext = path.extname(importedModule.url).toLowerCase();
if (STYLE_EXTENSIONS.has(ext)) {
// The SSR module is possibly not loaded. Load it if it's null.
const ssrModule =
importedModule.ssrModule ?? (await viteServer.ssrLoadModule(importedModule.url));
if (
mode === 'development' && // only inline in development
typeof importedModule.ssrModule?.default === 'string' // ignore JS module styles
typeof ssrModule?.default === 'string' // ignore JS module styles
) {
importedStylesMap.set(importedModule.url, importedModule.ssrModule.default);
importedStylesMap.set(importedModule.url, ssrModule.default);
} else {
// NOTE: We use the `url` property here. `id` would break Windows.
importedCssUrls.add(importedModule.url);