Skip to content

Commit b6fe5ed

Browse files
committed
Revert "try fix windows"
This reverts commit f1934f0.
1 parent bf4193a commit b6fe5ed

1 file changed

Lines changed: 13 additions & 29 deletions

File tree

packages/plugin-vite/src/plugins/server_snapshot.ts

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ export function serverSnapshot(options: ResolvedFreshViteConfig): Plugin[] {
408408
handler(_code, id) {
409409
if (server) {
410410
const ssrGraph = server.environments.ssr.moduleGraph;
411-
const mod = getSsrModule(server.environments.ssr, id);
411+
const mod = ssrGraph.getModuleById(id);
412412
if (mod === undefined) return;
413413

414414
const snapshot = ssrGraph.getModuleById("\0fresh:server-snapshot");
@@ -424,7 +424,10 @@ export function serverSnapshot(options: ResolvedFreshViteConfig): Plugin[] {
424424
if (name !== undefined) {
425425
const route = routes.get(name);
426426
if (route !== undefined) {
427-
route.css.push(mod.url);
427+
const mod = ssrGraph.getModuleById(id);
428+
if (mod !== undefined) {
429+
route.css.push(mod.url);
430+
}
428431

429432
const routeMod = ssrGraph.getModuleById(
430433
`\0fresh-route-css::${name}`,
@@ -609,14 +612,17 @@ async function collectRouteCss(
609612
if (seen.has(current)) continue;
610613
seen.add(current);
611614

612-
let mod = getSsrModule(env, current);
615+
// Modules may be registered under either their public id or Vite's
616+
// internal "\0" id, depending on when they entered the graph.
617+
let mod = env.moduleGraph.getModuleById(current) ??
618+
env.moduleGraph.getModuleById(`\0${current}`);
619+
613620
if (mod?.transformResult == null) {
614621
// Dev transforms are lazy. Force Vite to load the module before we
615622
// inspect its imports for CSS dependencies.
616-
await env.fetchModule(
617-
path.isAbsolute(current) ? path.toFileUrl(current).href : current,
618-
);
619-
mod = getSsrModule(env, current);
623+
await env.fetchModule(current);
624+
mod = env.moduleGraph.getModuleById(current) ??
625+
env.moduleGraph.getModuleById(`\0${current}`);
620626
}
621627

622628
// Some ids still won't resolve into the SSR graph (for example, if Vite
@@ -641,28 +647,6 @@ async function collectRouteCss(
641647
return Array.from(out);
642648
}
643649

644-
function getSsrModule(
645-
env: ViteDevServer["environments"]["ssr"],
646-
id: string,
647-
): EnvironmentModuleNode | undefined {
648-
// Real files are keyed by file path in Vite's module graph, while Fresh's
649-
// virtual route modules are addressed by their module ids.
650-
if (path.isAbsolute(id)) {
651-
const mods = env.moduleGraph.getModulesByFile(path.normalize(id));
652-
if (mods === undefined) return undefined;
653-
654-
for (const mod of mods) {
655-
if (mod.transformResult !== null) return mod;
656-
}
657-
658-
return mods.values().next().value;
659-
}
660-
661-
const mod = env.moduleGraph.getModuleById(id) ??
662-
env.moduleGraph.getModuleById(`\0${id}`);
663-
return mod;
664-
}
665-
666650
function walkUp(
667651
mod: EnvironmentModuleNode,
668652
fn: (mod: EnvironmentModuleNode) => boolean,

0 commit comments

Comments
 (0)