Skip to content

Commit 912f30c

Browse files
authored
fix(gatsby-plugin-image): Correctly handle formats in StaticImage (#28618)
* Include formats prop * Default to auto, webp * fix(gatsby-plugin-sharp): Include default transform options for webp * Update snapshots * Is this why it fails? * Allow time for other image * Use jpg-only for lazy-load tests. Lazy-load tests currently fail if there's a webp image. This will need a proper fix later, but not in this PR. This reverts commit 7f1cd2a.
1 parent 1e702ae commit 912f30c

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed

e2e-tests/gatsby-static-image/src/pages/lazy-loading.js

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default function NativeLazyLoadingPage() {
1111
height={59}
1212
alt="Citrus fruits"
1313
loading="lazy"
14+
formats={["jpg"]}
1415
/>
1516

1617
<div style={{ height: `5000px`, background: `#F4F4F4` }} />
@@ -22,6 +23,7 @@ export default function NativeLazyLoadingPage() {
2223
height={59}
2324
alt="Citrus fruits"
2425
loading="lazy"
26+
formats={["jpg"]}
2527
/>
2628
</div>
2729
)

packages/gatsby-plugin-image/src/babel-helpers.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import camelCase from "camelcase"
77
export const SHARP_ATTRIBUTES = new Set([
88
`src`,
99
`layout`,
10+
`formats`,
1011
`maxWidth`,
1112
`maxHeight`,
1213
`quality`,

packages/gatsby-plugin-sharp/src/image-data.ts

+2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ export async function generateImageData({
110110
quality,
111111
} = args
112112

113+
args.formats = args.formats || [`auto`, `webp`]
114+
113115
const {
114116
fit = `cover`,
115117
cropFocus = sharp.strategy.attention,

0 commit comments

Comments
 (0)