Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vercel): Fix srcset generation not working on Vercel #10756

Merged
merged 6 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/nine-radios-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@astrojs/vercel": patch
---

Fixes `widths` and `densities` not working when using Vercel's Image Optimization.

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.
4 changes: 3 additions & 1 deletion packages/integrations/vercel/src/image/build-service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { ExternalImageService } from 'astro';
import { isESMImportedImage, sharedValidateOptions } from './shared.js';
import { baseService } from 'astro/assets';

const service: ExternalImageService = {
...baseService,
validateOptions: (options, serviceOptions) =>
sharedValidateOptions(options, serviceOptions.service.config, 'production'),
getHTMLAttributes(options) {
Expand Down Expand Up @@ -29,7 +31,7 @@ const service: ExternalImageService = {
}
}

const { src, width, height, format, quality, ...attributes } = props;
const { src, width, height, format, quality, densities, widths, formats, ...attributes } = options;

return {
...attributes,
Expand Down
2 changes: 2 additions & 0 deletions packages/integrations/vercel/src/image/shared-dev-service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { LocalImageService } from 'astro';
import { baseService } from 'astro/assets';
import { sharedValidateOptions } from './shared.js';

export const baseDevService: Omit<LocalImageService, 'transform'> = {
...baseService,
validateOptions: (options, serviceOptions) =>
sharedValidateOptions(options, serviceOptions.service.config, 'development'),
getURL(options) {
Expand Down
Loading