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:
parent
63cd9d89e8
commit
0068afb876
2 changed files with 10 additions and 2 deletions
5
.changeset/smooth-hats-smell.md
Normal file
5
.changeset/smooth-hats-smell.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Ensure SSR module is loaded before testing if it's CSS in dev
|
|
@ -18,11 +18,14 @@ export async function getStylesForURL(
|
||||||
for await (const importedModule of crawlGraph(viteServer, viteID(filePath), true)) {
|
for await (const importedModule of crawlGraph(viteServer, viteID(filePath), true)) {
|
||||||
const ext = path.extname(importedModule.url).toLowerCase();
|
const ext = path.extname(importedModule.url).toLowerCase();
|
||||||
if (STYLE_EXTENSIONS.has(ext)) {
|
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 (
|
if (
|
||||||
mode === 'development' && // only inline in development
|
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 {
|
} else {
|
||||||
// NOTE: We use the `url` property here. `id` would break Windows.
|
// NOTE: We use the `url` property here. `id` would break Windows.
|
||||||
importedCssUrls.add(importedModule.url);
|
importedCssUrls.add(importedModule.url);
|
||||||
|
|
Loading…
Reference in a new issue