Skip to content
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

test(hmr): improve #3033 fix description #14645

Merged
merged 1 commit into from
Oct 16, 2023
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
6 changes: 5 additions & 1 deletion packages/vite/src/node/server/moduleGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ export class ModuleGraph {
mod.ssrModule = null
mod.ssrError = null

// Fix #3033
// https://github.com/vitejs/vite/issues/3033
// Given b.js -> c.js -> b.js (arrow means top-level import), if c.js self-accepts
// and refetches itself, the execution order becomes c.js -> b.js -> c.js. The import
// order matters here as it will fail. The workaround for now is to not hmr invalidate
// b.js so that c.js refetches the already cached b.js, skipping the import loop.
if (hmrBoundaries.includes(mod)) {
return
}
Expand Down
8 changes: 4 additions & 4 deletions playground/hmr/__tests__/hmr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -800,11 +800,11 @@ if (import.meta.hot) {
await untilUpdated(() => el.textContent(), '2')
})

test('issue-3033', async () => {
await page.goto(viteTestUrl + '/issue-3033/index.html')
const el = await page.$('.issue-3033')
test('hmr works for self-accepted module within circular imported files', async () => {
await page.goto(viteTestUrl + '/self-accept-within-circular/index.html')
const el = await page.$('.self-accept-within-circular')
expect(await el.textContent()).toBe('c')
editFile('issue-3033/c.js', (code) =>
editFile('self-accept-within-circular/c.js', (code) =>
code.replace(`export const c = 'c'`, `export const c = 'cc'`),
)
await untilUpdated(() => el.textContent(), 'cc')
Expand Down
2 changes: 0 additions & 2 deletions playground/hmr/issue-3033/index.html

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import './b'
export const c = 'c'

function render(content) {
document.querySelector('.issue-3033').textContent = content
document.querySelector('.self-accept-within-circular').textContent = content
}
render(c)

Expand Down
2 changes: 2 additions & 0 deletions playground/hmr/self-accept-within-circular/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<script type="module" src="index.js"></script>
<div class="self-accept-within-circular"></div>