Skip to content

Commit daabe72

Browse files
Improve CSS ?url HMR in RSC Framework Mode (#14237)
1 parent 02a7a3d commit daabe72

File tree

7 files changed

+66
-37
lines changed

7 files changed

+66
-37
lines changed

integration/helpers/rsc-vite-framework/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"@vanilla-extract/css": "^1.17.4",
2222
"@vanilla-extract/vite-plugin": "^5.1.1",
2323
"@vitejs/plugin-react": "^4.5.2",
24-
"@vitejs/plugin-rsc": "0.4.21",
24+
"@vitejs/plugin-rsc": "0.4.24",
2525
"cross-env": "^7.0.3",
2626
"typescript": "^5.1.6",
2727
"vite": "^6.2.0",

integration/helpers/rsc-vite/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"typecheck": "tsc"
1111
},
1212
"devDependencies": {
13-
"@vitejs/plugin-rsc": "0.4.21",
13+
"@vitejs/plugin-rsc": "0.4.24",
1414
"@types/express": "^5.0.0",
1515
"@types/node": "^22.13.1",
1616
"@types/react": "^19.1.8",

integration/vite-css-test.ts

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -547,29 +547,39 @@ async function hmrWorkflow({
547547
);
548548

549549
const testCases = [
550-
{ file: "styles-bundled.css", selector: "#css-bundled" },
550+
{
551+
file: "styles-bundled.css",
552+
selector: "#css-bundled",
553+
},
551554
// TODO: Fix HMR for CSS Modules in server-first routes in RSC Framework mode
552555
...(routeBase === "rsc-server-first-route"
553556
? []
554-
: [{ file: "styles.module.css", selector: "#css-modules" }]),
555-
// TODO: Fix HMR for `?url` CSS imports in RSC Framework mode: https://github.com/vitejs/vite-plugin-react/issues/772
556-
// Once fixed, check if this also fixes HMR for Vanilla Extract
557-
...(templateName.includes("rsc")
558-
? []
559-
: [
560-
{
561-
file: "styles-postcss-linked.css",
562-
selector: "#css-postcss-linked",
563-
},
557+
: ([
564558
{
565-
file: "styles-vanilla-global.css.ts",
566-
selector: "#css-vanilla-global",
559+
file: "styles.module.css",
560+
selector: "#css-modules",
567561
},
562+
] as const)),
563+
{
564+
file: "styles-postcss-linked.css",
565+
selector: "#css-postcss-linked",
566+
},
567+
{
568+
file: "styles-vanilla-global.css.ts",
569+
selector: "#css-vanilla-global",
570+
},
571+
// TODO: Fix HMR for locally scoped Vanilla Extract styles in RSC
572+
// Framework mode. May require changes to the RSC plugin, or Vanilla
573+
// Extract. Userland workaround for now:
574+
// https://github.com/pawelblaszczyk5/vite-rsc-experiments/blob/643649f2e6562c859d9612126bfc3a183e03c7b5/apps/vanilla-extract/vite.config.ts
575+
...(templateName.includes("rsc")
576+
? []
577+
: ([
568578
{
569579
file: "styles-vanilla-local.css.ts",
570580
selector: "#css-vanilla-local",
571581
},
572-
]),
582+
] as const)),
573583
] as const satisfies Array<{
574584
file: string;
575585
selector: string;
@@ -584,8 +594,15 @@ async function hmrWorkflow({
584594
`CSS update for ${routeFile}`,
585595
).toHaveCSS("padding", NEW_PADDING);
586596

587-
// TODO: Fix state preservation when changing CSS Modules in RSC Framework mode
588-
if (templateName.includes("rsc") && file === "styles.module.css") {
597+
// TODO: Fix state preservation when changing these styles in RSC
598+
// Framework mode. This appears to be a deeper HMR issue with
599+
// changing non-React modules imported by the route.
600+
if (
601+
templateName.includes("rsc") &&
602+
(file === "styles.module.css" ||
603+
file === "styles-postcss-linked.css" ||
604+
file === "styles-vanilla-global.css.ts")
605+
) {
589606
continue;
590607
}
591608

packages/react-router-dev/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"@babel/types": "^7.27.7",
7979
"@npmcli/package-json": "^4.0.1",
8080
"@react-router/node": "workspace:*",
81-
"@vitejs/plugin-rsc": "0.4.21",
81+
"@vitejs/plugin-rsc": "0.4.24",
8282
"arg": "^5.0.1",
8383
"babel-dead-code-elimination": "^1.0.6",
8484
"chokidar": "^4.0.0",

playground/rsc-vite-framework/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"@types/react": "^19.1.8",
1919
"@types/react-dom": "^19.1.6",
2020
"@vitejs/plugin-react": "^4.5.2",
21-
"@vitejs/plugin-rsc": "0.4.21",
21+
"@vitejs/plugin-rsc": "0.4.24",
2222
"cross-env": "^7.0.3",
2323
"remark-frontmatter": "^5.0.0",
2424
"remark-mdx-frontmatter": "^5.2.0",

playground/rsc-vite/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"@types/react": "^19.1.8",
1616
"@types/react-dom": "^19.1.6",
1717
"@vitejs/plugin-react": "^4.5.2",
18-
"@vitejs/plugin-rsc": "0.4.21",
18+
"@vitejs/plugin-rsc": "0.4.24",
1919
"cross-env": "^7.0.3",
2020
"typescript": "^5.1.6",
2121
"vite": "^6.2.0"

pnpm-lock.yaml

Lines changed: 28 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)