Skip to content

Commit faa2405

Browse files
patak-devdanielroe
andauthored
fix(preload): backport #18098, throw error preloading module as well (#18099)
Co-authored-by: Daniel Roe <[email protected]>
1 parent 54c55db commit faa2405

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

packages/vite/src/node/plugins/importAnalysisBuild.ts

+13-10
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,23 @@ function preload(
145145
)
146146
}
147147

148+
function handlePreloadError(err: Error) {
149+
const e = new Event('vite:preloadError', {
150+
cancelable: true,
151+
}) as VitePreloadErrorEvent
152+
e.payload = err
153+
window.dispatchEvent(e)
154+
if (!e.defaultPrevented) {
155+
throw err
156+
}
157+
}
158+
148159
return promise.then((res) => {
149160
for (const item of res || []) {
150161
if (item.status !== 'rejected') continue
151-
152-
const e = new Event('vite:preloadError', {
153-
cancelable: true,
154-
}) as VitePreloadErrorEvent
155-
e.payload = item.reason
156-
window.dispatchEvent(e)
157-
if (!e.defaultPrevented) {
158-
throw item.reason
159-
}
162+
handlePreloadError(item.reason)
160163
}
161-
return baseModule()
164+
return baseModule().catch(handlePreloadError)
162165
})
163166
}
164167

playground/js-sourcemap/__tests__/js-sourcemap.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ describe.runIf(isBuild)('build tests', () => {
140140
expect(formatSourcemapForSnapshot(JSON.parse(map))).toMatchInlineSnapshot(`
141141
{
142142
"ignoreList": [],
143-
"mappings": ";s8BAAA,OAAO,2BAAuB,EAAC,wBAE/B,QAAQ,IAAI,uBAAuB",
143+
"mappings": ";+8BAAA,OAAO,2BAAuB,EAAC,wBAE/B,QAAQ,IAAI,uBAAuB",
144144
"sources": [
145145
"../../after-preload-dynamic.js",
146146
],

0 commit comments

Comments
 (0)