Skip to content

Commit fef5dc4

Browse files
committed
Fix ?url CSS import HMR
1 parent c2fdb81 commit fef5dc4

File tree

2 files changed

+34
-33
lines changed

2 files changed

+34
-33
lines changed

integration/vite-css-test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,7 @@ async function hmrWorkflow({
599599
// changing non-React modules imported by the route.
600600
if (
601601
templateName.includes("rsc") &&
602-
(file === "styles-postcss-linked.css" ||
603-
file === "styles-vanilla-global.css.ts")
602+
file === "styles-vanilla-global.css.ts"
604603
) {
605604
continue;
606605
}

packages/react-router-dev/vite/rsc/plugins/hmr-invalidate-client-only-modules-in-rsc.ts

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,42 +20,44 @@ export function hmrInvalidateClientOnlyModulesInRsc(): Vite.Plugin {
2020
return;
2121
}
2222

23-
// Find the corresponding client module for this file so we can walk the
24-
// module graph
25-
const updatedClientModule =
26-
ctx.server.environments.client.moduleGraph.getModuleById(ctx.file);
27-
28-
// If this file is not in the client graph, it's not a client-only module
29-
// and we don't need to invalidate anything, so bail out
30-
if (!updatedClientModule) {
23+
// Find the corresponding client modules for this file so we can walk the
24+
// module graph looking for ancestors in the RSC graph
25+
const updatedClientModules =
26+
ctx.server.environments.client.moduleGraph.getModulesByFile(ctx.file);
27+
if (!updatedClientModules) {
3128
return;
3229
}
3330

34-
const visited = new Set<Vite.EnvironmentModuleNode>();
35-
const walk = (module: Vite.EnvironmentModuleNode) => {
36-
if (!module || visited.has(module) || !module.id) {
37-
return;
38-
}
39-
40-
visited.add(module);
41-
42-
// If this module is in the RSC graph, invalidate it and stop walking
43-
const serverModule = this.environment.moduleGraph.getModuleById(
44-
module.id,
45-
);
46-
if (serverModule) {
47-
this.environment.moduleGraph.invalidateModule(serverModule);
48-
return;
49-
}
50-
51-
if (module.importers) {
52-
for (const importer of module.importers) {
53-
walk(importer);
31+
for (const updatedClientModule of updatedClientModules) {
32+
const visited = new Set<Vite.EnvironmentModuleNode>();
33+
const walk = (module: Vite.EnvironmentModuleNode) => {
34+
if (visited.has(module) || !module.id) {
35+
return;
5436
}
55-
}
56-
};
5737

58-
walk(updatedClientModule);
38+
visited.add(module);
39+
40+
// Try to find this module in the RSC graph
41+
const serverModule = this.environment.moduleGraph.getModuleById(
42+
module.id,
43+
);
44+
45+
// If this module is in the RSC graph, invalidate it and stop walking
46+
if (serverModule) {
47+
this.environment.moduleGraph.invalidateModule(serverModule);
48+
return;
49+
}
50+
51+
// If we haven't found a corresponding RSC module, walk importers
52+
if (module.importers) {
53+
for (const importer of module.importers) {
54+
walk(importer);
55+
}
56+
}
57+
};
58+
59+
walk(updatedClientModule);
60+
}
5961
},
6062
};
6163
}

0 commit comments

Comments
 (0)