We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 21acfb2 + 23f2864 commit 7814f0cCopy full SHA for 7814f0c
src/runtime/utils/plugin.client.ts
@@ -4,14 +4,18 @@ export async function getImageSize(src: string) {
4
if (!dimensionCache.has(src)) {
5
const { width, height } = (await new Promise(resolve => {
6
let img: HTMLImageElement | undefined = new global.Image();
7
- img.onload = () => {
+
8
+ const resolvePromise = () => {
9
const dimension = {
10
width: img?.naturalWidth || 0,
11
height: img?.naturalHeight || 0
12
};
13
img = undefined;
14
resolve(dimension);
15
16
17
+ img.onload = () => resolvePromise();
18
+ img.onerror = () => resolvePromise();
19
img.src = src;
20
})) as { width: number; height: number };
21
dimensionCache.set(src, { width, height });
0 commit comments