Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
isSelfAccepting,
staticImportedUrls,
)
if (hasHMR && prunedImports) {
if (prunedImports) {
handlePrunedModules(prunedImports, environment)
}
}
Expand Down
9 changes: 9 additions & 0 deletions playground/hmr/__tests__/hmr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,15 @@ if (!isBuild) {
.toMatch('parent:child')
})

test('deleting import from non-self-accepting module can trigger prune event', async () => {
await page.goto(viteTestUrl)
await expect.poll(() => page.textContent('.prune')).toMatch('init')
editFile('prune/dep1.js', (code) =>
code.replace(`import './dep2.js'`, `// import './dep2.js'`),
)
await expect.poll(() => page.textContent('.prune')).toMatch('dep2-pruned')
})

test('import.meta.hot?.accept', async () => {
await page.goto(viteTestUrl)

Expand Down
1 change: 1 addition & 0 deletions playground/hmr/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import './file-delete-restore'
import './optional-chaining/parent'
import './intermediate-file-delete'
import './circular'
import './prune'
import logo from './logo.svg'
import logoNoInline from './logo-no-inline.svg'
import { msg as softInvalidationMsg } from './soft-invalidation'
Expand Down
1 change: 1 addition & 0 deletions playground/hmr/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@
<img id="logo" />
<img id="logo-no-inline" />
<div class="circular"></div>
<div class="prune">prune/init</div>
8 changes: 8 additions & 0 deletions playground/hmr/prune/dep1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import './dep2.js'

// TODO: https://github.com/vitejs/vite/issues/20781
// currently we need one more `import` in this module
// to trigger prune for depending module `dep2.js` since
// the prune event logic is skipped when `es-module-lexer`
// detects `imports.length === 0`
import './dep2-other.js'
Empty file.
5 changes: 5 additions & 0 deletions playground/hmr/prune/dep2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if (import.meta.hot) {
import.meta.hot.prune(() => {
document.querySelector('.prune').textContent = 'prune/dep2-pruned'
})
}
5 changes: 5 additions & 0 deletions playground/hmr/prune/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import './dep1.js'

if (import.meta.hot) {
import.meta.hot.accept(() => {})
}
Loading