Skip to content

Commit

Permalink
fix(gatsby-plugin-image): Correctly handle formats in StaticImage (#2…
Browse files Browse the repository at this point in the history
…8618) (#28630)

* 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.

(cherry picked from commit 912f30c)

Co-authored-by: Matt Kane <matt@gatsbyjs.com>
  • Loading branch information
LekoArts and ascorbic authored Dec 15, 2020
1 parent 7f43c3b commit eff15a1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions e2e-tests/gatsby-static-image/src/pages/lazy-loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default function NativeLazyLoadingPage() {
height={59}
alt="Citrus fruits"
loading="lazy"
formats={["jpg"]}
/>

<div style={{ height: `5000px`, background: `#F4F4F4` }} />
Expand All @@ -22,6 +23,7 @@ export default function NativeLazyLoadingPage() {
height={59}
alt="Citrus fruits"
loading="lazy"
formats={["jpg"]}
/>
</div>
)
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-plugin-image/src/babel-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import camelCase from "camelcase"
export const SHARP_ATTRIBUTES = new Set([
`src`,
`layout`,
`formats`,
`maxWidth`,
`maxHeight`,
`quality`,
Expand Down
2 changes: 2 additions & 0 deletions packages/gatsby-plugin-sharp/src/image-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ export async function generateImageData({
quality,
} = args

args.formats = args.formats || [`auto`, `webp`]

const {
fit = `cover`,
cropFocus = sharp.strategy.attention,
Expand Down

0 comments on commit eff15a1

Please sign in to comment.