Skip to content

Commit

Permalink
fix: enable backwards-compat of svg imports
Browse files Browse the repository at this point in the history
  • Loading branch information
stramel committed Sep 25, 2024
1 parent 5290098 commit 20db55b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/astro/src/assets/services/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AstroError, AstroErrorData } from '../../core/errors/index.js';
import { isRemotePath, joinPaths } from '../../core/path.js';
import { DEFAULT_HASH_PROPS, DEFAULT_OUTPUT_FORMAT, VALID_SUPPORTED_FORMATS } from '../consts.js';
import type { ImageOutputFormat, ImageTransform, UnresolvedSrcSetValue } from '../types.js';
import { isESMImportedImage } from '../utils/imageKind.js';
import { isESMImportedImage, isRemoteImage } from '../utils/imageKind.js';
import { isRemoteAllowed } from '../utils/remotePattern.js';

export type ImageService = LocalImageService | ExternalImageService;
Expand Down Expand Up @@ -142,7 +142,7 @@ export const baseService: Omit<LocalImageService, 'transform'> = {
propertiesToHash: DEFAULT_HASH_PROPS,
validateOptions(options) {
// `src` is missing or is `undefined`.
if (!options.src || (typeof options.src !== 'string' && typeof options.src !== 'object')) {
if (!options.src || (!isRemoteImage(options.src) && !isESMImportedImage(options.src))) {
throw new AstroError({
...AstroErrorData.ExpectedImage,
message: AstroErrorData.ExpectedImage.message(
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/assets/utils/imageKind.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ImageMetadata, UnresolvedImageTransform } from '../types.js';

export function isESMImportedImage(src: ImageMetadata | string): src is ImageMetadata {
return typeof src === 'object';
return typeof src === 'object' || (typeof src === 'function' && 'src' in src);
}

export function isRemoteImage(src: ImageMetadata | string): src is string {
Expand Down

0 comments on commit 20db55b

Please sign in to comment.