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

fix(hmr): cannot reload after missing import on server startup (#9534) #10602

Merged
merged 1 commit into from
Oct 25, 2022
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
2 changes: 2 additions & 0 deletions packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
if (ssr) {
return [url, url]
}
// fix#9534, prevent the importerModuleNode being stopped from propagating updates
importerModule.isSelfAccepting = false
return this.error(
`Failed to resolve import "${url}" from "${path.relative(
process.cwd(),
Expand Down
24 changes: 24 additions & 0 deletions playground/hmr/__tests__/hmr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,4 +670,28 @@ if (!isBuild) {
return await el.textContent()
}, '[wow]1')
})

test('keep hmr reload after missing import on server startup', async () => {
const file = 'missing-import/a.js'
const importCode = "import 'missing-modules'"
const unImportCode = `// ${importCode}`
const timeout = 2000

await page.goto(viteTestUrl + '/missing-import/index.html')

browserLogs.length = 0
expect(browserLogs).toMatchObject([])

editFile(file, (code) => code.replace(importCode, unImportCode))

await page.waitForNavigation({ timeout })
expect(browserLogs.some((msg) => msg.match('missing test'))).toBe(true)
browserLogs.length = 0

editFile(file, (code) => code.replace(unImportCode, importCode))

await page.waitForNavigation({ timeout })
expect(browserLogs.some((msg) => msg.includes('500'))).toBe(true)
browserLogs.length = 0
})
}
3 changes: 3 additions & 0 deletions playground/hmr/missing-import/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import 'missing-modules'

console.log('missing test')
2 changes: 2 additions & 0 deletions playground/hmr/missing-import/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<div>Page</div>
<script type="module" src="main.js"></script>
1 change: 1 addition & 0 deletions playground/hmr/missing-import/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './a.js'