Skip to content

Commit 3ba026d

Browse files
authored
fix(bundled-dev): handle lazy request error (#23291)
1 parent 02cffa9 commit 3ba026d

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎packages/vite/src/node/server/middlewares/triggerLazyBundling.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,17 @@ export function triggerLazyBundlingMiddleware(
2626

2727
const moduleId = params.get('id')
2828
const clientId = params.get('clientId')
29-
const result = await bundledDev.triggerLazyBundling(moduleId, clientId)
29+
let result: { code: string; filename: string } | undefined
30+
try {
31+
result = await bundledDev.triggerLazyBundling(moduleId, clientId)
32+
} catch (e) {
33+
server.config.logger.error(
34+
`Failed to trigger lazy bundling for ${moduleId} (clientId: ${clientId}):` +
35+
e,
36+
{ error: e },
37+
)
38+
return next(new Error(`Failed to trigger lazy bundling`))
39+
}
3040
if (result == null) {
3141
return next()
3242
}

‎playground/hmr-full-bundle-mode/__tests__/hmr-full-bundle-mode.spec.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,13 @@ if (isBuild) {
448448
.toBe('worker-plain-updated')
449449
})
450450

451+
test('lazy bundling errors return 500', async () => {
452+
const response = await page.request.get(
453+
new URL('/@vite/lazy?id=%2Ffoo%2Fbar&clientId=x', page.url()).href,
454+
)
455+
expect(response.status()).toBe(500)
456+
})
457+
451458
// Blocked by https://github.com/rolldown/rolldown/issues/10340
452459
test.skip('chained invalidate in an import cycle settles', async () => {
453460
const original = readFile('cycle-a.js')

0 commit comments

Comments
 (0)