From 0068afb876342ae76154e552dfc5bb6832b665ed Mon Sep 17 00:00:00 2001 From: Allan Chain <36528777+AllanChain@users.noreply.github.com> Date: Tue, 6 Sep 2022 20:25:26 +0800 Subject: [PATCH] fix: ensure SSR module is loaded before testing is CSS (#4621) --- .changeset/smooth-hats-smell.md | 5 +++++ packages/astro/src/core/render/dev/css.ts | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 .changeset/smooth-hats-smell.md diff --git a/.changeset/smooth-hats-smell.md b/.changeset/smooth-hats-smell.md new file mode 100644 index 0000000000..cac2f8befc --- /dev/null +++ b/.changeset/smooth-hats-smell.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Ensure SSR module is loaded before testing if it's CSS in dev diff --git a/packages/astro/src/core/render/dev/css.ts b/packages/astro/src/core/render/dev/css.ts index cfbfa7114d..9c10cb03cd 100644 --- a/packages/astro/src/core/render/dev/css.ts +++ b/packages/astro/src/core/render/dev/css.ts @@ -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);