Skip to content

Commit

Permalink
feat: emit event to handle chunk load errors (#12084)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Jun 15, 2023
1 parent 8fe6952 commit 2eca54e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion packages/vite/src/node/plugins/importAnalysisBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,17 @@ function preload(
})
}
}),
).then(() => baseModule())
)
.then(() => baseModule())
.catch((err) => {
const e = new Event('vite:preloadError', { cancelable: true })
// @ts-expect-error custom payload
e.payload = err
window.dispatchEvent(e)
if (!e.defaultPrevented) {
throw err
}
})
}

/**
Expand Down
2 changes: 1 addition & 1 deletion playground/js-sourcemap/__tests__/js-sourcemap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe.runIf(isBuild)('build tests', () => {
const map = findAssetFile(/after-preload-dynamic.*\.js\.map/)
expect(formatSourcemapForSnapshot(JSON.parse(map))).toMatchInlineSnapshot(`
{
"mappings": "stBAAAA,EAAA,WAAO,2BAAuB,EAAC,sEAE/B,QAAQ,IAAI,uBAAuB",
"mappings": "41BAAAA,EAAA,WAAO,2BAAuB,EAAC,sEAE/B,QAAQ,IAAI,uBAAuB",
"sources": [
"../../after-preload-dynamic.js",
],
Expand Down

0 comments on commit 2eca54e

Please sign in to comment.