0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-30 22:03:56 -05:00

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>
This commit is contained in:
Timon Jurschitsch 2024-10-16 12:47:37 +02:00 committed by GitHub
parent 5a4edebfd2
commit a3d30a602a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
fix: improve error message when inferSize is used in local images with the Image component

View file

@ -1,3 +1,4 @@
import { isRemotePath } from '@astrojs/internal-helpers/path';
import type { AstroConfig } from '../@types/astro.js';
import { AstroError, AstroErrorData } from '../core/errors/index.js';
import { DEFAULT_HASH_PROPS } from './consts.js';
@ -65,7 +66,11 @@ export async function getImage(
};
// Infer size for remote images if inferSize is true
if (options.inferSize && isRemoteImage(resolvedOptions.src)) {
if (
options.inferSize &&
isRemoteImage(resolvedOptions.src) &&
isRemotePath(resolvedOptions.src)
) {
const result = await inferRemoteSize(resolvedOptions.src); // Directly probe the image URL
resolvedOptions.width ??= result.width;
resolvedOptions.height ??= result.height;