Skip to content
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
6 changes: 6 additions & 0 deletions .changeset/easy-dingos-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'astro': patch
'@astrojs/netlify': patch
---

Fixes a bug where remote image dimensions were not validated during static builds on Netlify.
1 change: 1 addition & 0 deletions packages/astro/src/assets/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { isESMImportedImage, isRemoteImage, resolveSrc } from './utils/imageKind
import { inferRemoteSize } from './utils/remoteProbe.js';
import { createPlaceholderURL, stringifyPlaceholderURL } from './utils/url.js';

export { verifyOptions } from './services/service.js';
export const cssFitValues = ['fill', 'contain', 'cover', 'scale-down'];

export async function getConfiguredImageService(): Promise<ImageService> {
Expand Down
3 changes: 3 additions & 0 deletions packages/integrations/netlify/src/image-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ExternalImageService } from 'astro';
import { baseService } from 'astro/assets';
import { verifyOptions } from '../../../astro/dist/assets/internal.js';
import { isESMImportedImage } from 'astro/assets/utils';
import { AstroError } from 'astro/errors';

Expand Down Expand Up @@ -51,6 +52,8 @@ const service: ExternalImageService = {
getHTMLAttributes: baseService.getHTMLAttributes,
getSrcSet: baseService.getSrcSet,
validateOptions(options) {
verifyOptions(options);

if (options.format && !SUPPORTED_FORMATS.includes(options.format)) {
throw new AstroError(
`Unsupported image format "${options.format}"`,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineConfig } from 'astro/config';
import netlify from '@astrojs/netlify';

export default defineConfig({
adapter: netlify(),
output: 'static',
image: {
service: {
entrypoint: 'astro/assets/services/sharp'
}
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "image-missing-dimention",
"type": "module",
"private": true,
"dependencies": {
"astro": "workspace:*",
"@astrojs/netlify": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
import { Image } from 'astro:assets';
---

<Image
src="https://images.unsplash.com/photo-1567674867291-b2595ac53ab4"
alt="Astro"
/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { loadFixture } from '../../../../astro/test/test-utils.js';

describe('Image validation when is not size specification in netlify.', () => {
it('throw on missing dimension in static build', async () => {
const fixture = await loadFixture({
root: new URL('./fixtures/image-missing-dimension/', import.meta.url)
});

try{
await fixture.build();
assert.fail();
} catch (e) {
// check the error image about missing image dimension
assert.match(
e.name,
/MissingImageDimension/,
`Build failed but not with the expected "MissingImageDimension"`
)
}
})
})
11 changes: 11 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading