Skip to content

Commit 35c7f35

Browse files
authored
fix: avoid using Promise.allSettled in preload function (#19805)
1 parent 9abe82f commit 35c7f35

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

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

+15-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,21 @@ function preload(
9595
// in that case fallback to getAttribute
9696
const cspNonce = cspNonceMeta?.nonce || cspNonceMeta?.getAttribute('nonce')
9797

98-
promise = Promise.allSettled(
98+
// Promise.allSettled is not supported by Chrome 64-75, Firefox 67-70, Safari 11.1-12.1
99+
function allSettled<T>(
100+
promises: Array<T | PromiseLike<T>>,
101+
): Promise<PromiseSettledResult<T>[]> {
102+
return Promise.all(
103+
promises.map((p) =>
104+
Promise.resolve(p).then(
105+
(value: T) => ({ status: 'fulfilled' as const, value }),
106+
(reason: unknown) => ({ status: 'rejected' as const, reason }),
107+
),
108+
),
109+
)
110+
}
111+
112+
promise = allSettled(
99113
deps.map((dep) => {
100114
// @ts-expect-error assetsURL is declared before preload.toString()
101115
dep = assetsURL(dep, importerUrl)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe.runIf(isBuild)('build tests', () => {
143143
{
144144
"debugId": "00000000-0000-0000-0000-000000000000",
145145
"ignoreList": [],
146-
"mappings": ";+8BAAA,OAAO,2BAAuB,0BAE9B,QAAQ,IAAI,uBAAuB",
146+
"mappings": ";4kCAAA,OAAO,2BAAuB,0BAE9B,QAAQ,IAAI,uBAAuB",
147147
"sources": [
148148
"../../after-preload-dynamic.js",
149149
],

0 commit comments

Comments
 (0)