Skip to content

Add RSC Framework Mode HMR/HDR support #14100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Aug 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
431 changes: 431 additions & 0 deletions integration/vite-hmr-hdr-rsc-test.ts

Large diffs are not rendered by default.

48 changes: 40 additions & 8 deletions integration/vite-hmr-hdr-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,27 @@ import path from "node:path";
import type { Page, PlaywrightWorkerOptions } from "@playwright/test";
import { expect } from "@playwright/test";

import type { Files } from "./helpers/vite.js";
import type { Files, TemplateName } from "./helpers/vite.js";
import {
test,
createEditor,
EXPRESS_SERVER,
viteConfig,
viteMajorTemplates,
reactRouterConfig,
} from "./helpers/vite.js";

const templates = [
...viteMajorTemplates,
{
templateName: "rsc-vite-framework",
templateDisplayName: "RSC Framework Mode",
},
] as const satisfies ReadonlyArray<{
templateName: TemplateName;
templateDisplayName: string;
}>;

const indexRoute = `
// imports
import { useState, useEffect } from "react";
Expand Down Expand Up @@ -40,28 +52,36 @@ const indexRoute = `
`;

test.describe("Vite HMR & HDR", () => {
viteMajorTemplates.forEach(({ templateName, templateDisplayName }) => {
templates.forEach(({ templateName, templateDisplayName }) => {
test.describe(templateDisplayName, () => {
test("vite dev", async ({ page, browserName, dev }) => {
let files: Files = async ({ port }) => ({
"vite.config.js": await viteConfig.basic({ port }),
"vite.config.js": await viteConfig.basic({ port, templateName }),
"react-router.config.ts": reactRouterConfig({
viteEnvironmentApi: templateName.includes("rsc"),
}),
"app/routes/_index.tsx": indexRoute,
});
let { cwd, port } = await dev(files, templateName);
await workflow({ page, browserName, cwd, port });
await workflow({ templateName, page, browserName, cwd, port });
});

test("express", async ({ page, browserName, customDev }) => {
test.skip(templateName.includes("rsc"), "RSC is not supported");
let files: Files = async ({ port }) => ({
"vite.config.js": await viteConfig.basic({ port }),
"vite.config.js": await viteConfig.basic({ port, templateName }),
"react-router.config.ts": reactRouterConfig({
viteEnvironmentApi: templateName.includes("rsc"),
}),
"server.mjs": EXPRESS_SERVER({ port }),
"app/routes/_index.tsx": indexRoute,
});
let { cwd, port } = await customDev(files, templateName);
await workflow({ page, browserName, cwd, port });
await workflow({ templateName, page, browserName, cwd, port });
});

test("mdx", async ({ page, dev }) => {
test.skip(templateName.includes("rsc"), "RSC is not supported");
let files: Files = async ({ port }) => ({
"vite.config.ts": `
import { defineConfig } from "vite";
Expand Down Expand Up @@ -120,11 +140,13 @@ test.describe("Vite HMR & HDR", () => {
});

async function workflow({
templateName,
page,
browserName,
cwd,
port,
}: {
templateName: TemplateName;
page: Page;
browserName: PlaywrightWorkerOptions["browserName"];
cwd: string;
Expand All @@ -145,7 +167,12 @@ async function workflow({

// setup: browser state
let hmrStatus = page.locator("#index [data-hmr]");
await expect(page).toHaveTitle("HMR updated title: 0");

// RSC doesn't support meta export?
if (!templateName.includes("rsc")) {
await expect(page).toHaveTitle("HMR updated title: 0");
}

await expect(hmrStatus).toHaveText("HMR updated: 0");
let input = page.locator("#index input");
await expect(input).toBeVisible();
Expand All @@ -159,7 +186,12 @@ async function workflow({
.replace("HMR updated: 0", "HMR updated: 1"),
);
await page.waitForLoadState("networkidle");
await expect(page).toHaveTitle("HMR updated title: 1");

// RSC doesn't support meta export?
if (!templateName.includes("rsc")) {
await expect(page).toHaveTitle("HMR updated title: 1");
}

await expect(hmrStatus).toHaveText("HMR updated: 1");
await expect(input).toHaveValue("stateful");
expect(page.errors).toEqual([]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import "virtual:react-router/unstable_rsc/inject-hmr-runtime";

import { startTransition, StrictMode } from "react";
import { hydrateRoot } from "react-dom/client";
import {
Expand Down
1 change: 0 additions & 1 deletion packages/react-router-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
"@babel/types": "^7.27.7",
"@npmcli/package-json": "^4.0.1",
"@react-router/node": "workspace:*",
"@vitejs/plugin-react": "^4.5.2",
"@vitejs/plugin-rsc": "0.4.11",
"arg": "^5.0.1",
"babel-dead-code-elimination": "^1.0.6",
Expand Down
16 changes: 15 additions & 1 deletion packages/react-router-dev/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ const entry = [
"vite/cloudflare.ts",
];

const external = ["./static/refresh-utils.mjs", /\.json$/];
const external = [
"./static/refresh-utils.mjs",
"./static/rsc-refresh-utils.mjs",
/\.json$/,
];

export default defineConfig([
{
Expand All @@ -39,6 +43,16 @@ export default defineConfig([
"dist/static/refresh-utils.mjs",
);

await fsp.mkdir("dist/static", { recursive: true });
await fsp.copyFile(
"vite/static/refresh-utils.mjs",
"dist/static/refresh-utils.mjs",
);
await fsp.copyFile(
"vite/static/rsc-refresh-utils.mjs",
"dist/static/rsc-refresh-utils.mjs",
);

await fsp.mkdir("dist/config/defaults", { recursive: true });
const files = await fsp.readdir("config/defaults");
for (const file of files) {
Expand Down
Loading
Loading