Skip to content

Commit a3d30a6

Browse files
DerTimoniusPrincesseuh
andauthoredOct 16, 2024··
fix: improve error for inferSize and Image component (#11823)
* fix: improve error for inferSize and Image component * add changeset * move isRemovePath check --------- Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
1 parent 5a4edeb commit a3d30a6

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed
 

‎.changeset/lazy-flowers-destroy.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
fix: improve error message when inferSize is used in local images with the Image component

‎packages/astro/src/assets/internal.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isRemotePath } from '@astrojs/internal-helpers/path';
12
import type { AstroConfig } from '../@types/astro.js';
23
import { AstroError, AstroErrorData } from '../core/errors/index.js';
34
import { DEFAULT_HASH_PROPS } from './consts.js';
@@ -65,7 +66,11 @@ export async function getImage(
6566
};
6667

6768
// Infer size for remote images if inferSize is true
68-
if (options.inferSize && isRemoteImage(resolvedOptions.src)) {
69+
if (
70+
options.inferSize &&
71+
isRemoteImage(resolvedOptions.src) &&
72+
isRemotePath(resolvedOptions.src)
73+
) {
6974
const result = await inferRemoteSize(resolvedOptions.src); // Directly probe the image URL
7075
resolvedOptions.width ??= result.width;
7176
resolvedOptions.height ??= result.height;

0 commit comments

Comments
 (0)
Please sign in to comment.