Skip to content

Commit 4a8f193

Browse files
moonclavedevascorbicflorian-lefebvre
authored
fix(vercel): handle SVG images correctly in build image service (#13679)
Co-authored-by: Matt Kane <[email protected]> Co-authored-by: Florian Lefebvre <[email protected]>
1 parent c947c28 commit 4a8f193

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

.changeset/dull-pots-laugh.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/vercel': patch
3+
---
4+
5+
Handle SVG images correctly in build image service

packages/integrations/vercel/src/image/build-service.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { ExternalImageService } from 'astro';
22
import { baseService } from 'astro/assets';
3-
import { isESMImportedImage, sharedValidateOptions } from './shared.js';
3+
import { sharedValidateOptions } from './shared.js';
4+
import { isESMImportedImage } from 'astro/assets/utils';
45

56
const service: ExternalImageService = {
67
...baseService,
@@ -43,6 +44,12 @@ const service: ExternalImageService = {
4344
};
4445
},
4546
getURL(options) {
47+
// For SVG files, return the original source path
48+
if (isESMImportedImage(options.src) && options.src.format === 'svg') {
49+
return options.src.src;
50+
}
51+
52+
// For non-SVG files, continue with the Vercel image processing
4653
const fileSrc = isESMImportedImage(options.src)
4754
? removeLeadingForwardSlash(options.src.src)
4855
: options.src;

packages/integrations/vercel/src/image/shared.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import type { AstroConfig, ImageMetadata, ImageQualityPreset, ImageTransform } from 'astro';
1+
import type { AstroConfig, ImageQualityPreset, ImageTransform } from 'astro';
2+
import { isESMImportedImage } from 'astro/assets/utils';
23

34
export function getDefaultImageConfig(astroImageConfig: AstroConfig['image']): VercelImageConfig {
45
return {
@@ -9,10 +10,6 @@ export function getDefaultImageConfig(astroImageConfig: AstroConfig['image']): V
910
};
1011
}
1112

12-
export function isESMImportedImage(src: ImageMetadata | string): src is ImageMetadata {
13-
return typeof src === 'object';
14-
}
15-
1613
export type DevImageService = 'sharp' | (string & {});
1714

1815
// https://vercel.com/docs/build-output-api/v3/configuration#images

0 commit comments

Comments
 (0)