Skip to content

Commit

Permalink
fix: ensure SSR module is loaded before testing is CSS (#4621)
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanChain authored Sep 6, 2022
1 parent 63cd9d8 commit 0068afb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-hats-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Ensure SSR module is loaded before testing if it's CSS in dev
7 changes: 5 additions & 2 deletions packages/astro/src/core/render/dev/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0068afb

Please sign in to comment.