Skip to content

Commit b312c95

Browse files
committed
fix: exclude css with ? import sideeffects from ssr
1 parent f208bd6 commit b312c95

2 files changed

Lines changed: 7 additions & 29 deletions

File tree

packages/start/src/server/collect-styles.ts

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -72,37 +72,13 @@ async function findModuleDependencies(
7272
// Vite doesn't expose these so we just copy the list for now
7373
// https://github.com/vitejs/vite/blob/d6bde8b03d433778aaed62afc2be0630c8131908/packages/vite/src/node/constants.ts#L49C23-L50
7474
const cssFileRegExp =
75-
/\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
75+
/\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)$/;
7676
// https://github.com/vitejs/vite/blob/d6bde8b03d433778aaed62afc2be0630c8131908/packages/vite/src/node/plugins/css.ts#L160
7777
const cssModulesRegExp = new RegExp(`\\.module${cssFileRegExp.source}`);
7878

7979
const isCssFile = (file: string) => cssFileRegExp.test(file);
8080
export const isCssModulesFile = (file: string) => cssModulesRegExp.test(file);
8181

82-
// https://github.com/remix-run/remix/blob/65326e39099f3b2285d83aecfe734ba35f668396/packages/remix-dev/vite/styles.ts#L29
83-
const cssUrlParamsWithoutSideEffects = ["url", "inline", "raw", "inline-css"];
84-
export const isCssUrlWithoutSideEffects = (url: string) => {
85-
const queryString = url.split("?")[1];
86-
87-
if (!queryString) {
88-
return false;
89-
}
90-
91-
const params = new URLSearchParams(queryString);
92-
for (const paramWithoutSideEffects of cssUrlParamsWithoutSideEffects) {
93-
if (
94-
// Parameter is blank and not explicitly set, i.e. "?url", not "?url="
95-
params.get(paramWithoutSideEffects) === "" &&
96-
!url.includes(`?${paramWithoutSideEffects}=`) &&
97-
!url.includes(`&${paramWithoutSideEffects}=`)
98-
) {
99-
return true;
100-
}
101-
}
102-
103-
return false;
104-
};
105-
10682
async function findFilesDepedencies(
10783
vite: DevEnvironment,
10884
files: Array<string>,
@@ -133,7 +109,7 @@ export async function findStylesInModuleGraph(
133109
const styles: Record<string, any> = {};
134110

135111
for (const dep of dependencies) {
136-
if (isCssFile(dep.url) && dep.id) {
112+
if (dep.id && isCssFile(dep.url)) {
137113
styles[dep.id] = dep.url;
138114
}
139115
}

packages/start/src/server/manifest/prod-ssr-manifest.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { clientViteManifest } from "solid-start:client-vite-manifest";
22
import { join } from "pathe";
3+
import { Manifest } from "vite";
34
import type { Asset } from "../renderAsset.tsx";
45

56
// Only reads from client manifest atm, might need server support for islands
@@ -67,7 +68,7 @@ function createHtmlTagsForAssets(assets: string[]) {
6768
}
6869

6970
function findAssetsInViteManifest(
70-
manifest: any,
71+
manifest: Manifest,
7172
id: string,
7273
assetMap = new Map(),
7374
stack: string[] = [],
@@ -86,7 +87,8 @@ function findAssetsInViteManifest(
8687
}
8788

8889
const assets = [
89-
...(chunk.assets?.filter(Boolean) || []),
90+
// TODO: Needs a better way to detect ?url
91+
...(chunk.assets?.filter(a => !a.endsWith('.css')) || []),
9092
...(chunk.css?.filter(Boolean) || []),
9193
];
9294
if (chunk.imports) {
@@ -95,7 +97,7 @@ function findAssetsInViteManifest(
9597
assets.push(
9698
...findAssetsInViteManifest(
9799
manifest,
98-
chunk.imports[i],
100+
chunk.imports[i]!,
99101
assetMap,
100102
stack,
101103
),

0 commit comments

Comments
 (0)