From 98fbc4115848347eac77bad32ec8f6bf02f047e9 Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch Date: Fri, 23 Aug 2024 14:01:29 +0200 Subject: [PATCH 1/3] fix: improve error for inferSize and Image component --- packages/astro/src/assets/utils/imageKind.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/astro/src/assets/utils/imageKind.ts b/packages/astro/src/assets/utils/imageKind.ts index 7b42f9f7017f..f45f573dc512 100644 --- a/packages/astro/src/assets/utils/imageKind.ts +++ b/packages/astro/src/assets/utils/imageKind.ts @@ -1,11 +1,12 @@ import type { ImageMetadata, UnresolvedImageTransform } from '../types.js'; +import { isRemotePath } from '@astrojs/internal-helpers/path'; export function isESMImportedImage(src: ImageMetadata | string): src is ImageMetadata { return typeof src === 'object'; } export function isRemoteImage(src: ImageMetadata | string): src is string { - return typeof src === 'string'; + return typeof src === 'string' && isRemotePath(src); } export async function resolveSrc(src: UnresolvedImageTransform['src']) { From 535ca254fd8dbcda895b97ee15bcefef21acb72b Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch Date: Fri, 23 Aug 2024 14:04:39 +0200 Subject: [PATCH 2/3] add changeset --- .changeset/lazy-flowers-destroy.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/lazy-flowers-destroy.md diff --git a/.changeset/lazy-flowers-destroy.md b/.changeset/lazy-flowers-destroy.md new file mode 100644 index 000000000000..b08525b18401 --- /dev/null +++ b/.changeset/lazy-flowers-destroy.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +fix: improve error message when inferSize is used in local images with the Image component From e60d3052f815ef9e53d080cabfd66f420d564753 Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch Date: Sat, 12 Oct 2024 16:46:03 +0200 Subject: [PATCH 3/3] move isRemovePath check --- packages/astro/src/assets/internal.ts | 7 ++++++- packages/astro/src/assets/utils/imageKind.ts | 3 +-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/astro/src/assets/internal.ts b/packages/astro/src/assets/internal.ts index 4cc85799c154..58cd41f43235 100644 --- a/packages/astro/src/assets/internal.ts +++ b/packages/astro/src/assets/internal.ts @@ -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; diff --git a/packages/astro/src/assets/utils/imageKind.ts b/packages/astro/src/assets/utils/imageKind.ts index d8295ca5adc6..e3e1b3341a4b 100644 --- a/packages/astro/src/assets/utils/imageKind.ts +++ b/packages/astro/src/assets/utils/imageKind.ts @@ -1,12 +1,11 @@ import type { ImageMetadata, UnresolvedImageTransform } from '../types.js'; -import { isRemotePath } from '@astrojs/internal-helpers/path'; export function isESMImportedImage(src: ImageMetadata | string): src is ImageMetadata { return typeof src === 'object'; } export function isRemoteImage(src: ImageMetadata | string): src is string { - return typeof src === 'string' && isRemotePath(src); + return typeof src === 'string'; } export async function resolveSrc(src: UnresolvedImageTransform['src']) {