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(gatsby-plugin-image): Correctly handle formats in StaticImage #28618

Merged
merged 9 commits into from
Dec 15, 2020
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 @@ -6,6 +6,7 @@ import { getAttributeValues } from "babel-jsx-utils"
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