Skip to content
This repository was archived by the owner on Jul 24, 2025. It is now read-only.

Commit e8dd1e2

Browse files
committed
fix: avoid key collision in React refresh registration
1 parent d43f7d0 commit e8dd1e2

11 files changed

Lines changed: 114 additions & 2 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { expect, test } from "@playwright/test";
2+
import { setupDevServer } from "../../utils";
3+
4+
test("Shadow export HMR", async ({ page }) => {
5+
const { testUrl, server, editFile } = await setupDevServer("shadow-export");
6+
await page.goto(testUrl);
7+
8+
editFile("src/App.tsx", ["Shadow export", "Shadow export updates!"]);
9+
await expect(page.locator("body")).toHaveText("Shadow export updates!");
10+
11+
await server.close();
12+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite + React + shadow export</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/index.tsx"></script>
12+
</body>
13+
</html>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "playground-worker",
3+
"private": true,
4+
"scripts": {
5+
"dev": "vite",
6+
"build": "vite build"
7+
},
8+
"dependencies": {
9+
"react": "^18.2.0",
10+
"react-dom": "^18.2.0"
11+
},
12+
"devDependencies": {
13+
"@types/react": "^18.0.27",
14+
"@types/react-dom": "^18.0.10",
15+
"@vitejs/plugin-react-swc": "../../dist"
16+
}
17+
}
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { memo } from "react";
2+
3+
function App() {
4+
return <div>Shadow export</div>;
5+
}
6+
7+
// For anyone reading this, don't do that
8+
// Use PascalCase for all components and export them directly without rename,
9+
// you're just making grep more complex.
10+
const withMemo = memo(App);
11+
export { withMemo as App };
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { StrictMode } from "react";
2+
import { createRoot } from "react-dom/client";
3+
import { App } from "./App";
4+
5+
createRoot(document.getElementById("root")!).render(
6+
<StrictMode>
7+
<App />
8+
</StrictMode>,
9+
);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"include": ["src", "vite.config.ts"],
3+
"compilerOptions": {
4+
"module": "ESNext",
5+
"lib": ["ESNext", "DOM", "DOM.Iterable"],
6+
"target": "ESNext",
7+
"jsx": "react-jsx",
8+
"types": ["vite/client"],
9+
"noEmit": true,
10+
"isolatedModules": true,
11+
"skipLibCheck": true,
12+
13+
/* Imports */
14+
"moduleResolution": "node", // Allow `index` imports
15+
"resolveJsonModule": true, // Allow json import
16+
"forceConsistentCasingInFileNames": true, // Avoid difference in case between file name and import
17+
18+
/* Linting */
19+
"strict": true,
20+
"noUnusedLocals": true,
21+
"noUnusedParameters": true,
22+
"noFallthroughCasesInSwitch": true,
23+
"useUnknownInCatchVariables": true
24+
}
25+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { defineConfig } from "vite";
2+
import react from "@vitejs/plugin-react-swc";
3+
4+
export default defineConfig({
5+
plugins: [react()],
6+
});

playground/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const setupDevServer = async (name: string) => {
5252
let content = readFileSync(path, "utf-8");
5353
for (let [search, replace] of replacements) {
5454
if (!content.includes(search)) {
55-
throw new Error(`${search} not found in ${name}`);
55+
throw new Error(`'${search}' not found in ${name}`);
5656
}
5757
content = content.replace(search, replace);
5858
}

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)