Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: emit event to handle chunk load errors #12084

Merged
merged 4 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Comment on lines +142 to +144
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to call preventDefault() on the event. Please avoid commenting on old PRs. You can create a Discussion instead for these questions (linking to a PR if you'd like)

})
}

/**
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