Skip to content

Commit 7814f0c

Browse files
authored
Merge pull request #1344 from codeflorist/bugfix/unresolved-promise
fix: resolve promise `onerror` in addition to `onload` in `getImageSize`
2 parents 21acfb2 + 23f2864 commit 7814f0c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/runtime/utils/plugin.client.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ export async function getImageSize(src: string) {
44
if (!dimensionCache.has(src)) {
55
const { width, height } = (await new Promise(resolve => {
66
let img: HTMLImageElement | undefined = new global.Image();
7-
img.onload = () => {
7+
8+
const resolvePromise = () => {
89
const dimension = {
910
width: img?.naturalWidth || 0,
1011
height: img?.naturalHeight || 0
1112
};
1213
img = undefined;
1314
resolve(dimension);
1415
};
16+
17+
img.onload = () => resolvePromise();
18+
img.onerror = () => resolvePromise();
1519
img.src = src;
1620
})) as { width: number; height: number };
1721
dimensionCache.set(src, { width, height });

0 commit comments

Comments
 (0)