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 1 commit
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 @@ -68,6 +69,10 @@ export const GatsbyImageHydrator: FunctionComponent<GatsbyImageProps> = function
}
return null
}
if (`class` in props) {
className = props.class
delete props.class
}
ascorbic marked this conversation as resolved.
Show resolved Hide resolved
const { width, height, layout, images } = image

const root = useRef<HTMLElement>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ export const GatsbyImage: FunctionComponent<GatsbyImageProps> = function GatsbyI
console.warn(`[gatsby-plugin-image] Missing image prop`)
return null
}
if (`class` in props) {
className = props.class
delete props.class
}
ascorbic marked this conversation as resolved.
Show resolved Hide resolved
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