-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support HMR for class components (#203)
- Loading branch information
1 parent
21eef9e
commit 53878df
Showing
12 changed files
with
135 additions
and
6 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
playground/class-components/__tests__/class-components.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { expect, test } from "@playwright/test"; | ||
import { setupDevServer, setupWaitForLogs } from "../../utils.ts"; | ||
|
||
test("Class component HMR", async ({ page }) => { | ||
const { testUrl, server, editFile } = | ||
await setupDevServer("class-components"); | ||
const waitForLogs = await setupWaitForLogs(page); | ||
await page.goto(testUrl); | ||
|
||
await expect(page.locator("body")).toHaveText("Hello World"); | ||
editFile("src/App.tsx", ["World", "class components"]); | ||
await waitForLogs("[vite] hot updated: /src/App.tsx"); | ||
await expect(page.locator("body")).toHaveText("Hello class components"); | ||
|
||
editFile("src/utils.tsx", ["Hello", "Hi"]); | ||
await waitForLogs("[vite] hot updated: /src/App.tsx"); | ||
await expect(page.locator("body")).toHaveText("Hi class components"); | ||
|
||
await server.close(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + React + class components</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/index.tsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "class-components", | ||
"type": "module", | ||
"private": true, | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.2.48", | ||
"@types/react-dom": "^18.2.18", | ||
"@vitejs/plugin-react-swc": "../../dist" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Component } from "react"; | ||
import { getGetting } from "./utils.tsx"; | ||
|
||
export class App extends Component { | ||
render() { | ||
return <span>{getGetting()} World</span>; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { StrictMode } from "react"; | ||
import { createRoot } from "react-dom/client"; | ||
import { App } from "./App.tsx"; | ||
|
||
createRoot(document.getElementById("root")!).render( | ||
<StrictMode> | ||
<App /> | ||
</StrictMode>, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const getGetting = () => <span>Hello</span>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"include": ["src", "vite.config.ts"], | ||
"compilerOptions": { | ||
"module": "ESNext", | ||
"lib": ["ESNext", "DOM", "DOM.Iterable"], | ||
"target": "ESNext", | ||
"jsx": "react-jsx", | ||
"types": ["vite/client"], | ||
"noEmit": true, | ||
"isolatedModules": true, | ||
"skipLibCheck": true, | ||
"moduleResolution": "bundler", | ||
"allowImportingTsExtensions": true, | ||
"resolveJsonModule": true, | ||
|
||
/* Linting */ | ||
"strict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"useUnknownInCatchVariables": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { defineConfig } from "vite"; | ||
import react from "@vitejs/plugin-react-swc"; | ||
|
||
export default defineConfig({ | ||
plugins: [react()], | ||
}); |
Binary file removed
BIN
-8.55 MB
...mponents/.swc/plugins/v4/007754343d0bfdb6fe27959c3405e5aee674e896788e641f88b94ed88e0d5e47
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters