fix(preload): throw error preloading module as well (#18098)

This commit is contained in:
Daniel Roe 2024-09-13 09:43:10 +01:00 committed by GitHub
parent b897cb8d0d
commit ba56cf43b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 11 deletions

View File

@ -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)
})
}

View File

@ -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",
],