mirror of
https://github.com/vitejs/vite.git
synced 2024-11-21 22:59:10 +00:00
fix(preload): throw error preloading module as well (#18098)
This commit is contained in:
parent
b897cb8d0d
commit
ba56cf43b5
@ -145,20 +145,23 @@ function preload(
|
||||
)
|
||||
}
|
||||
|
||||
function handlePreloadError(err: Error) {
|
||||
const e = new Event('vite:preloadError', {
|
||||
cancelable: true,
|
||||
}) as VitePreloadErrorEvent
|
||||
e.payload = err
|
||||
window.dispatchEvent(e)
|
||||
if (!e.defaultPrevented) {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
return promise.then((res) => {
|
||||
for (const item of res || []) {
|
||||
if (item.status !== 'rejected') continue
|
||||
|
||||
const e = new Event('vite:preloadError', {
|
||||
cancelable: true,
|
||||
}) as VitePreloadErrorEvent
|
||||
e.payload = item.reason
|
||||
window.dispatchEvent(e)
|
||||
if (!e.defaultPrevented) {
|
||||
throw item.reason
|
||||
}
|
||||
handlePreloadError(item.reason)
|
||||
}
|
||||
return baseModule()
|
||||
return baseModule().catch(handlePreloadError)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,7 @@ describe.runIf(isBuild)('build tests', () => {
|
||||
expect(formatSourcemapForSnapshot(JSON.parse(map))).toMatchInlineSnapshot(`
|
||||
{
|
||||
"ignoreList": [],
|
||||
"mappings": ";s8BAAA,OAAO,2BAAuB,EAAC,wBAE/B,QAAQ,IAAI,uBAAuB",
|
||||
"mappings": ";+8BAAA,OAAO,2BAAuB,EAAC,wBAE/B,QAAQ,IAAI,uBAAuB",
|
||||
"sources": [
|
||||
"../../after-preload-dynamic.js",
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user