Skip to content

Commit 8992a2f

Browse files
committed
fix: fix css module on ssr environment
1 parent 2af36d5 commit 8992a2f

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

packages/plugin-rsc/src/plugin.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,7 +1973,8 @@ function vitePluginRscCss(
19731973
},
19741974
},
19751975
{
1976-
// self accept css module imported in rsc environment to avoid full reload
1976+
// force self accepting "?direct" css (injected via SSR `<link />`) to avoid full reload.
1977+
// this should only apply to css modules
19771978
// https://github.com/vitejs/vite/blob/84079a84ad94de4c1ef4f1bdb2ab448ff2c01196/packages/vite/src/node/plugins/css.ts#L1096
19781979
name: 'rsc:rsc-css-self-accept',
19791980
apply: 'serve',
@@ -1986,20 +1987,9 @@ function vitePluginRscCss(
19861987
isCSSRequest(id)
19871988
) {
19881989
const mod = this.environment.moduleGraph.getModuleById(id)
1989-
const { filename, query } = parseIdQuery(id)
1990-
if (mod && !mod.isSelfAccepting && 'direct' in query) {
1991-
const serverMods =
1992-
manager.server.environments.rsc!.moduleGraph.getModulesByFile(
1993-
filename,
1994-
)
1995-
// filter out module nodes created by tailwind dependenncy.
1996-
// for Vite 7.1, we can use `m.type !== "asset"`.
1997-
const isServerCss = [...(serverMods ?? [])].some((m) =>
1998-
[...m.importers].some((m) => m.id && !isCSSRequest(m.id)),
1999-
)
2000-
if (isServerCss) {
2001-
mod.isSelfAccepting = true
2002-
}
1990+
const parsed = parseIdQuery(id)
1991+
if (mod && !mod.isSelfAccepting && 'direct' in parsed.query) {
1992+
mod.isSelfAccepting = true
20031993
}
20041994
}
20051995
},

0 commit comments

Comments
 (0)