Skip to content

Commit

Permalink
fix: add list of SSR-able file extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
bholmesdev committed Apr 15, 2022
1 parent ce7a955 commit 13df9b2
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions packages/astro/src/core/render/dev/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import path from 'path';
import { unwrapId, viteID } from '../../util.js';
import { STYLE_EXTENSIONS } from '../util.js';

/**
* List of file extensions signalling we can (and should) SSR ahead-of-time
* See usage below
*/
const fileExtensionsToSSR = new Set(['.md']);

/** Given a filePath URL, crawl Vite’s module graph to find all style imports. */
export async function getStylesForURL(
filePath: URL,
Expand Down Expand Up @@ -33,13 +39,14 @@ export async function getStylesForURL(
continue;
}
if (id === entry.id) {
let upToDateEntry = entry;
if (!entry.ssrTransformResult) {
await viteServer.ssrLoadModule(entry.id);
upToDateEntry = viteServer.moduleGraph.getModuleById(id) ?? entry;
}
scanned.add(id);
for (const importedModule of upToDateEntry.importedModules) {
for (const importedModule of entry.importedModules) {
// some dynamically imported modules are *not* server rendered in time
// to only SSR modules that we can safely transform, we check against
// a list of file extensions based on our built-in vite plugins
if (importedModule.id && fileExtensionsToSSR.has(path.extname(importedModule.id))) {
await viteServer.ssrLoadModule(importedModule.id);
}
importedModules.add(importedModule);
}
}
Expand Down

0 comments on commit 13df9b2

Please sign in to comment.