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.
onerror
onload
getImageSize
1 parent 21acfb2 commit 23f2864Copy full SHA for 23f2864
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