Skip to content

Commit c75eded

Browse files
authored
fix(vercel): Fix srcset generation not working on Vercel (#10756)
* fix(vercel): Fix `srcset` generation not working on Vercel * chore: changeset * fix: remove densities and widths from the HTML attributes * nit: better changeset * nit: add formats
1 parent 17c2bb1 commit c75eded

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

.changeset/nine-radios-peel.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@astrojs/vercel": patch
3+
---
4+
5+
Fixes `widths` and `densities` not working when using Vercel's Image Optimization.
6+
7+
Note that you still need to make sure that the widths you're outputting are enabled in [the `imageConfig` property of the Vercel adapter](https://docs.astro.build/en/guides/integrations-guide/vercel/#imagesconfig) in order for these properties to work.

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import type { ExternalImageService } from 'astro';
22
import { isESMImportedImage, sharedValidateOptions } from './shared.js';
3+
import { baseService } from 'astro/assets';
34

45
const service: ExternalImageService = {
6+
...baseService,
57
validateOptions: (options, serviceOptions) =>
68
sharedValidateOptions(options, serviceOptions.service.config, 'production'),
79
getHTMLAttributes(options) {
@@ -29,7 +31,7 @@ const service: ExternalImageService = {
2931
}
3032
}
3133

32-
const { src, width, height, format, quality, ...attributes } = props;
34+
const { src, width, height, format, quality, densities, widths, formats, ...attributes } = options;
3335

3436
return {
3537
...attributes,

packages/integrations/vercel/src/image/shared-dev-service.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import type { LocalImageService } from 'astro';
2+
import { baseService } from 'astro/assets';
23
import { sharedValidateOptions } from './shared.js';
34

45
export const baseDevService: Omit<LocalImageService, 'transform'> = {
6+
...baseService,
57
validateOptions: (options, serviceOptions) =>
68
sharedValidateOptions(options, serviceOptions.service.config, 'development'),
79
getURL(options) {

0 commit comments

Comments
 (0)