Skip to content

Commit 3d6446c

Browse files
authored
fix(gatsby-plugin-image): Correct image styles (#28834)
* fix(gatsby-plugin-image): Correct image styles * Remove avif options from dom * Remove in/delete
1 parent a9c933a commit 3d6446c

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

packages/gatsby-plugin-image/src/components/gatsby-image.browser.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface GatsbyImageProps
2727
alt: string
2828
as?: ElementType
2929
className?: string
30+
class?: string
3031
imgClassName?: string
3132
image: IGatsbyImageData
3233
imgStyle?: CSSProperties
@@ -56,6 +57,7 @@ export const GatsbyImageHydrator: FunctionComponent<GatsbyImageProps> = function
5657
as: Type = `div`,
5758
style,
5859
className,
60+
class: preactClass,
5961
onStartLoad,
6062
image,
6163
onLoad: customOnLoad,
@@ -68,6 +70,9 @@ export const GatsbyImageHydrator: FunctionComponent<GatsbyImageProps> = function
6870
}
6971
return null
7072
}
73+
if (preactClass) {
74+
className = preactClass
75+
}
7176
const { width, height, layout, images } = image
7277

7378
const root = useRef<HTMLElement>()

packages/gatsby-plugin-image/src/components/gatsby-image.server.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const GatsbyImageHydrator: FunctionComponent<{
1818
export const GatsbyImage: FunctionComponent<GatsbyImageProps> = function GatsbyImage({
1919
as,
2020
className,
21+
class: preactClass,
2122
style,
2223
image,
2324
loading = `lazy`,
@@ -32,6 +33,15 @@ export const GatsbyImage: FunctionComponent<GatsbyImageProps> = function GatsbyI
3233
console.warn(`[gatsby-plugin-image] Missing image prop`)
3334
return null
3435
}
36+
if (preactClass) {
37+
className = preactClass
38+
}
39+
imgStyle = {
40+
objectFit,
41+
objectPosition,
42+
backgroundColor,
43+
...imgStyle,
44+
}
3545

3646
const {
3747
width,
@@ -97,6 +107,8 @@ export const GatsbyImage: FunctionComponent<GatsbyImageProps> = function GatsbyI
97107
<MainImage
98108
data-gatsby-image-ssr=""
99109
sizes={sizes}
110+
className={imgClassName}
111+
style={imgStyle}
100112
{...(props as Omit<MainImageProps, "images" | "fallback">)}
101113
// When eager is set we want to start the isLoading state on true (we want to load the img without react)
102114
{...getMainProps(loading === `eager`, false, cleanedImages, loading)}

packages/gatsby-plugin-image/src/components/static-image.server.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export function _getStaticImage(
5353
jpgOptions,
5454
pngOptions,
5555
webpOptions,
56+
avifOptions,
5657
blurredOptions,
5758
/* eslint-enable @typescript-eslint/no-unused-vars */
5859
...props

0 commit comments

Comments
 (0)