-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
gatsby-image: art-directing multiple images might not show the correct image at a breakpoint depending on the ordering of the media key #17528
Comments
media
key
media
key
I've updated the title/description regarding this issue. And I also created a demo project that would reproduce this issue https://github.com/kimbaudi/gatsby-image-art-directing-issue. Please take a look at the following 2 files:
Both pages are nearly identical except for the ordering of the To understand the bug, you need to build the project and run it on your local machine. When you resize the browser window so that the width is less than 768px, the 480px wide When you resize the browser window so that the width is between 768px and 1024px (inclusive), the 768px wide When you resize the browser window so that the width is 1025px or greater, the 1024px wide Also, notice that when you go to http://localhost:8000/it-works/, everything works as expected. |
👋 @kimbaudi ! I'm curious if this issue persists if you are more explicit about the const images = {
bustAZoo: [
{
...data.smBustAZoo.childImageSharp.fluid,
media: `(max-width: 767px)`,
},
{
...data.lgBustAZoo.childImageSharp.fluid,
media: `(min-width: 1024px)`,
},
{
...data.mdBustAZoo.childImageSharp.fluid,
media: `(min-width: 768px) and (max-width: 1023px)`,
},
],
}
return (<Img fluid={images.bustAZoo} alt="Bust A Zoo" /> Without having looked too closely at your specific issue, ordering can play a role in how these If this does solve your issue, we may want to update the documentation to explicitly call this out. cc @polarathene |
@brimtown - I agree that this issue is best resolved by specifying more explicit We should update the documentation by replacing the example with another example that provides more explicit |
Description
gatsby-image plugin added a new art direction feature (see #13395 and Art-directing multiple images).
This new feature allows different images to show at different breakpoints (aka art direction).
However, art-directing multiple images might not show the correct image at a given breakpoint depending on the ordering of the media key.
For example, suppose I have an image
bust-a-zoo.png
that has 1080px width and 810px height.And suppose I have the following graphql query:
Now, if I define the array of images along with the
media
key per image like the following, it doesn't work as expected:But, if I re-order the array like the following, it now works as expected:
Steps to reproduce
I've created a demo project that reproduces the issue: https://github.com/kimbaudi/gatsby-image-art-directing-issue
git clone https://github.com/kimbaudi/gatsby-image-art-directing-issue.git
)npm i && npm start
)bust-a-zoo.png
image and open in a new tab.Expected result
The image should be 1024px wide because I configured gatsby-image art-directing to show the 1024px wide image with media query
(min-width: 1024px)
Actual result
The image is actually 768px wide despite configuring gatsby-image art-directing to show the 1024px wide image with media query
(min-width: 1024px)
. Just because of the ordering of the array 😞Environment
The text was updated successfully, but these errors were encountered: