Skip to content

Commit 1b5ccf1

Browse files
authored
Merge branch 'main' into 09-14-fix_rsc_remove_server_style_when_css_import_is_removed
2 parents a3a0caf + 78a3f56 commit 1b5ccf1

File tree

1 file changed

+3
-37
lines changed

1 file changed

+3
-37
lines changed

packages/plugin-rsc/src/plugin.ts

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,6 +2129,9 @@ function vitePluginRscCss(
21292129
const importer = parsed.id
21302130
if (this.environment.mode === 'dev') {
21312131
const result = collectCss(server.environments.rsc!, importer)
2132+
for (const file of [importer, ...result.visitedFiles]) {
2133+
this.addWatchFile(file)
2134+
}
21322135
const cssHrefs = result.hrefs.map((href) => href.slice(1))
21332136
const deps = assetsURLOfDeps({ css: cssHrefs, js: [] }, manager)
21342137
return generateResourcesCode(
@@ -2150,20 +2153,6 @@ function vitePluginRscCss(
21502153
}
21512154
}
21522155
},
2153-
hotUpdate(ctx) {
2154-
if (this.environment.name === 'rsc') {
2155-
const { server } = manager
2156-
const mods = collectModuleDependents(ctx.modules)
2157-
for (const mod of mods) {
2158-
if (mod.id) {
2159-
invalidteModuleById(
2160-
server.environments.rsc!,
2161-
`\0` + toCssVirtual({ id: mod.id, type: 'rsc' }),
2162-
)
2163-
}
2164-
}
2165-
}
2166-
},
21672156
},
21682157
createVirtualPlugin(
21692158
'vite-rsc/remove-duplicate-server-css',
@@ -2198,29 +2187,6 @@ export default function RemoveDuplicateServerCss() {
21982187
]
21992188
}
22002189

2201-
function invalidteModuleById(environment: DevEnvironment, id: string) {
2202-
const mod = environment.moduleGraph.getModuleById(id)
2203-
if (mod) {
2204-
environment.moduleGraph.invalidateModule(mod)
2205-
}
2206-
return mod
2207-
}
2208-
2209-
function collectModuleDependents(mods: EnvironmentModuleNode[]) {
2210-
const visited = new Set<EnvironmentModuleNode>()
2211-
function recurse(mod: EnvironmentModuleNode) {
2212-
if (visited.has(mod)) return
2213-
visited.add(mod)
2214-
for (const importer of mod.importers) {
2215-
recurse(importer)
2216-
}
2217-
}
2218-
for (const mod of mods) {
2219-
recurse(mod)
2220-
}
2221-
return [...visited]
2222-
}
2223-
22242190
function generateResourcesCode(depsCode: string, manager: RscPluginManager) {
22252191
const ResourcesFn = (
22262192
React: typeof import('react'),

0 commit comments

Comments
 (0)