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
5 changes: 5 additions & 0 deletions .changeset/fluffy-seas-shine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Correct types to allow `priority` on all images
20 changes: 11 additions & 9 deletions packages/astro/src/assets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ type ImageSharedProps<T> = T & {
* ```
*/
quality?: ImageQuality;

/**
* If true, the image will be loaded with a higher priority. This can be useful for images that are visible above the fold. There should usually be only one image with `priority` set to `true` per page.
* All other images will be lazy-loaded according to when they are in the viewport.
* **Example**:
* ```astro
* <Image src={...} priority alt="..." />
* ```
*/
priority?: boolean;

} & (
| {
/**
Expand Down Expand Up @@ -201,15 +212,6 @@ type ImageSharedProps<T> = T & {
*/

position?: string;
/**
* If true, the image will be loaded with a higher priority. This can be useful for images that are visible above the fold. There should usually be only one image with `priority` set to `true` per page.
* All other images will be lazy-loaded according to when they are in the viewport.
* **Example**:
* ```astro
* <Image src={...} priority alt="..." />
* ```
*/
priority?: boolean;

/**
* A list of widths to generate images for. The value of this property will be used to assign the `srcset` property on the final `img` element.
Expand Down
7 changes: 7 additions & 0 deletions packages/astro/test/core-image.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ describe('astro:image', () => {
assert.equal(res.headers.get('content-type'), 'image/webp');
});

it('includes priority loading attributes', () => {
let $img = $('#priority img');
assert.equal($img.attr('loading'), 'eager');
assert.equal($img.attr('decoding'), 'sync');
assert.equal($img.attr('fetchpriority'), 'high');
});

it('properly skip processing SVGs, but does not error', async () => {
let res = await fixture.fetch('/svgSupport');
let html = await res.text();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@ import myImage from "../assets/penguin1.jpg";
<div id="encoded-chars">
<Image src="https://avatars.githubusercontent.com/u%2f622227?s=64" alt="fred2" width="48" height="48" />
</div>

<div id="priority">
<Image src={myImage} alt="a penguin" priority densities={[1,2]}/>
</div>
</body>
</html>
4 changes: 4 additions & 0 deletions packages/astro/test/fixtures/core-image/src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import myImage from "../assets/penguin1.jpg";
<Image src={myImage} alt="a penguin" />
</div>

<div id="priority">
<Image src={myImage} alt="a penguin" priority densities={[1,2]}/>
</div>

<div id="local-width">
<Image src={myImage} alt="a penguin" width={350} />
</div>
Expand Down
Loading