-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Daniel Roe <[email protected]>
- Loading branch information
Showing
2 changed files
with
13 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,8 @@ function preload( | |
deps?: string[], | ||
importerUrl?: string, | ||
) { | ||
let promise: Promise<unknown> = Promise.resolve() | ||
let promise: Promise<PromiseSettledResult<unknown>[] | void> = | ||
Promise.resolve() | ||
// @ts-expect-error __VITE_IS_MODERN__ will be replaced with boolean later | ||
if (__VITE_IS_MODERN__ && deps && deps.length > 0) { | ||
const links = document.getElementsByTagName('link') | ||
|
@@ -93,7 +94,7 @@ function preload( | |
// in that case fallback to getAttribute | ||
const cspNonce = cspNonceMeta?.nonce || cspNonceMeta?.getAttribute('nonce') | ||
|
||
promise = Promise.all( | ||
promise = Promise.allSettled( | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
patak-dev
Author
Member
|
||
deps.map((dep) => { | ||
// @ts-expect-error assetsURL is declared before preload.toString() | ||
dep = assetsURL(dep, importerUrl) | ||
|
@@ -144,18 +145,21 @@ function preload( | |
) | ||
} | ||
|
||
return promise | ||
.then(() => baseModule()) | ||
.catch((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 = err | ||
e.payload = item.reason | ||
window.dispatchEvent(e) | ||
if (!e.defaultPrevented) { | ||
throw err | ||
throw item.reason | ||
} | ||
}) | ||
} | ||
return baseModule() | ||
}) | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Promise.allSettled seems have some compatibility problem in some browser, would this be ok
https://caniuse.com/?search=allSettled