-
-
Notifications
You must be signed in to change notification settings - Fork 190
feat: add hmr support for compound components #518
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
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2ed4961
feat: add hmr support for compound components
Newbie012 8093da0
remove unused code
Newbie012 1479a1d
cleanup
Newbie012 2600829
move outside of if
Newbie012 ed7d870
cleanup
Newbie012 ea0279d
revert
Newbie012 d820a5a
Merge branch 'main' into main
Newbie012 5403fd4
update lockfile
Newbie012 f526d3d
Move isCompoundComponent to its own function
ArnaudBarre cb02fe9
fix for-of
ArnaudBarre 0c104ba
Merge remote-tracking branch 'origin/main' into Newbie012/main
ArnaudBarre d18a7f5
Fix lock
ArnaudBarre fe10694
Remove vite dep from playground
ArnaudBarre db32d06
Add changelog
ArnaudBarre 711fa8c
Review
ArnaudBarre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
27 changes: 27 additions & 0 deletions
27
playground/compound-components/__tests__/compound-components.spec.ts
This file contains hidden or 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,27 @@ | ||
| import { expect, test } from 'vitest' | ||
| import { editFile, isServe, page, untilBrowserLogAfter } from '~utils' | ||
|
|
||
| test('should render compound components', async () => { | ||
| expect(await page.textContent('h1')).toMatch('Compound Components HMR Test') | ||
| expect(await page.textContent('h3')).toMatch('Accordion Root') | ||
| }) | ||
|
|
||
| if (isServe) { | ||
| test('compound components should use HMR instead of full reload', async () => { | ||
| const logs = await untilBrowserLogAfter( | ||
| () => | ||
| editFile('src/Accordion.tsx', (code) => | ||
| code.replace('Accordion Root', 'Accordion Root Updated'), | ||
| ), | ||
| /\[vite\]/, | ||
| ) | ||
|
|
||
| expect(logs).toContain('[vite] hot updated: /src/Accordion.tsx') | ||
| expect(logs).not.toContain('[vite] invalidate') | ||
|
|
||
| // revert changes | ||
| editFile('src/Accordion.tsx', (code) => | ||
| code.replace('Accordion Root Updated', 'Accordion Root'), | ||
| ) | ||
| }) | ||
| } |
This file contains hidden or 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> | ||
ArnaudBarre marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <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>Compound Components Test</title> | ||
| </head> | ||
| <body> | ||
| <div id="root"></div> | ||
| <script type="module" src="/src/main.tsx"></script> | ||
| </body> | ||
| </html> | ||
This file contains hidden or 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,21 @@ | ||
| { | ||
| "name": "@vitejs/test-compound-components", | ||
| "private": true, | ||
| "version": "0.0.0", | ||
| "type": "module", | ||
| "scripts": { | ||
| "dev": "vite", | ||
| "build": "vite build", | ||
| "serve": "vite preview" | ||
| }, | ||
| "dependencies": { | ||
| "react": "^19.1.0", | ||
| "react-dom": "^19.1.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/react": "^19.1.8", | ||
| "@types/react-dom": "^19.1.6", | ||
| "@vitejs/plugin-react": "workspace:*", | ||
| "typescript": "^5.8.3" | ||
| } | ||
| } |
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 hidden or 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,36 @@ | ||
| import React from 'react' | ||
|
|
||
| const Root: React.FC<{ children: React.ReactNode }> = ({ children }) => { | ||
| return ( | ||
| <div | ||
| style={{ | ||
| border: '1px solid #ccc', | ||
| borderRadius: '4px', | ||
| margin: '16px 0', | ||
| }} | ||
| > | ||
| <h3 style={{ padding: '12px', margin: '0', backgroundColor: '#f5f5f5' }}> | ||
| Accordion Root | ||
| </h3> | ||
| <div style={{ padding: '12px' }}>{children}</div> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| const Item: React.FC<{ children: React.ReactNode }> = ({ children }) => { | ||
| return ( | ||
| <div | ||
| style={{ | ||
| padding: '8px 12px', | ||
| border: '1px solid #e0e0e0', | ||
| margin: '4px 0', | ||
| borderRadius: '2px', | ||
| backgroundColor: '#fafafa', | ||
| }} | ||
| > | ||
| {children} | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export const Accordion = { Root, Item } |
This file contains hidden or 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,21 @@ | ||
| import React from 'react' | ||
| import ReactDOM from 'react-dom/client' | ||
| import { Accordion } from './Accordion' | ||
|
|
||
| const root = ReactDOM.createRoot(document.getElementById('root')!) | ||
|
|
||
| root.render( | ||
| <React.StrictMode> | ||
| <div> | ||
| <h1>Compound Components HMR Test</h1> | ||
| <p> | ||
| This demonstrates the compound component pattern that causes full reload | ||
| instead of HMR. | ||
| </p> | ||
| <Accordion.Root> | ||
| <Accordion.Item>First Item</Accordion.Item> | ||
| <Accordion.Item>Second Item</Accordion.Item> | ||
| </Accordion.Root> | ||
| </div> | ||
| </React.StrictMode>, | ||
| ) |
This file contains hidden or 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,25 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "ES2020", | ||
| "useDefineForClassFields": true, | ||
| "lib": ["ES2020", "DOM", "DOM.Iterable"], | ||
| "module": "ESNext", | ||
| "skipLibCheck": true, | ||
| "types": ["vite/client"], | ||
|
|
||
| /* Bundler mode */ | ||
| "moduleResolution": "bundler", | ||
| "allowImportingTsExtensions": true, | ||
| "resolveJsonModule": true, | ||
| "isolatedModules": true, | ||
| "noEmit": true, | ||
| "jsx": "react-jsx", | ||
|
|
||
| /* Linting */ | ||
| "strict": true, | ||
| "noUnusedLocals": true, | ||
| "noUnusedParameters": true, | ||
| "noFallthroughCasesInSwitch": true | ||
| }, | ||
| "include": ["src", "vite.config.ts"] | ||
| } |
This file contains hidden or 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,14 @@ | ||
| import react from '@vitejs/plugin-react' | ||
| import type { UserConfig } from 'vite' | ||
|
|
||
| const config: UserConfig = { | ||
| server: { port: 8907 /* Should be unique */ }, | ||
| mode: 'development', | ||
ArnaudBarre marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| plugins: [react()], | ||
| build: { | ||
| // to make tests faster | ||
| minify: false, | ||
| }, | ||
| } | ||
|
|
||
| export default config | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.