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): Correct image styles #28834

Merged
merged 3 commits into from
Jan 4, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface GatsbyImageProps
alt: string
as?: ElementType
className?: string
class?: string
imgClassName?: string
image: IGatsbyImageData
imgStyle?: CSSProperties
Expand Down Expand Up @@ -56,6 +57,7 @@ export const GatsbyImageHydrator: FunctionComponent<GatsbyImageProps> = function
as: Type = `div`,
style,
className,
class: preactClass,
onStartLoad,
image,
onLoad: customOnLoad,
Expand All @@ -68,6 +70,9 @@ export const GatsbyImageHydrator: FunctionComponent<GatsbyImageProps> = function
}
return null
}
if (preactClass) {
className = preactClass
}
const { width, height, layout, images } = image

const root = useRef<HTMLElement>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const GatsbyImageHydrator: FunctionComponent<{
export const GatsbyImage: FunctionComponent<GatsbyImageProps> = function GatsbyImage({
as,
className,
class: preactClass,
style,
image,
loading = `lazy`,
Expand All @@ -32,6 +33,15 @@ export const GatsbyImage: FunctionComponent<GatsbyImageProps> = function GatsbyI
console.warn(`[gatsby-plugin-image] Missing image prop`)
return null
}
if (preactClass) {
className = preactClass
}
imgStyle = {
objectFit,
objectPosition,
backgroundColor,
...imgStyle,
}

const {
width,
Expand Down Expand Up @@ -97,6 +107,8 @@ export const GatsbyImage: FunctionComponent<GatsbyImageProps> = function GatsbyI
<MainImage
data-gatsby-image-ssr=""
sizes={sizes}
className={imgClassName}
style={imgStyle}
{...(props as Omit<MainImageProps, "images" | "fallback">)}
// When eager is set we want to start the isLoading state on true (we want to load the img without react)
{...getMainProps(loading === `eager`, false, cleanedImages, loading)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function _getStaticImage(
jpgOptions,
pngOptions,
webpOptions,
avifOptions,
blurredOptions,
/* eslint-enable @typescript-eslint/no-unused-vars */
...props
Expand Down