Skip to content

Commit 6a811f1

Browse files
committed
refactor(rsc): opt-out of soft invaldiation of virtual modules
1 parent 8adfeb5 commit 6a811f1

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

packages/plugin-rsc/src/plugin.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,9 +2102,10 @@ function vitePluginRscCss(
21022102
const importer = parsed.id
21032103
if (this.environment.mode === 'dev') {
21042104
const result = collectCss(server.environments.rsc!, importer)
2105-
for (const file of [importer, ...result.visitedFiles]) {
2106-
this.addWatchFile(file)
2107-
}
2105+
// for (const file of [importer, ...result.visitedFiles]) {
2106+
// this.addWatchFile(file)
2107+
// }
2108+
this.addWatchFile(importer)
21082109
const cssHrefs = result.hrefs.map((href) => href.slice(1))
21092110
const deps = assetsURLOfDeps({ css: cssHrefs, js: [] }, manager)
21102111
return generateResourcesCode(
@@ -2126,6 +2127,18 @@ function vitePluginRscCss(
21262127
}
21272128
}
21282129
},
2130+
configureServer(server) {
2131+
// opt-out of soft invalidation of virtual modules to ensure re-executing `load`
2132+
const moduleGraph = server.environments.rsc!.moduleGraph
2133+
const original = moduleGraph.invalidateModule
2134+
moduleGraph.invalidateModule = function (...args) {
2135+
if (args[0].id && parseCssVirtual(args[0].id)) {
2136+
// @ts-ignore
2137+
args[4] = false
2138+
}
2139+
return original.apply(this, args)
2140+
}
2141+
},
21292142
},
21302143
createVirtualPlugin(
21312144
'vite-rsc/remove-duplicate-server-css',

0 commit comments

Comments
 (0)