Skip to content

Commit

Permalink
fix: improve error for inferSize and Image component (#11823)
Browse files Browse the repository at this point in the history
* fix: improve error for inferSize and Image component

* add changeset

* move isRemovePath check

---------

Co-authored-by: Erika <[email protected]>
  • Loading branch information
DerTimonius and Princesseuh authored Oct 16, 2024
1 parent 5a4edeb commit a3d30a6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/lazy-flowers-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

fix: improve error message when inferSize is used in local images with the Image component
7 changes: 6 additions & 1 deletion packages/astro/src/assets/internal.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a3d30a6

Please sign in to comment.