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

[gatsby-image] Art direction in not working as expected. #29074

Closed
HenrikDK2 opened this issue Jan 18, 2021 · 3 comments
Closed

[gatsby-image] Art direction in not working as expected. #29074

HenrikDK2 opened this issue Jan 18, 2021 · 3 comments
Labels
status: needs reproduction This issue needs a simplified reproduction of the bug for further troubleshooting. type: bug An issue or pull request relating to a bug in Gatsby

Comments

@HenrikDK2
Copy link

HenrikDK2 commented Jan 18, 2021

Similar #17528

Images are not following the media queries rules when more than 2 images are present in the array.

const sources = [
    mobile.childImageSharp.fluid,
    {
      ...tablet.childImageSharp.fluid,
      media: `(min-width: 500px)`,
    },
    {
      ...desktopSmall.childImageSharp.fluid,
      media: `(min-width: 950px)`,
    },
    {
      ...desktop.childImageSharp.fluid,
      media: `(min-width: 1200px)`,
    },
  ];

The above renders the tablet image at 500px, and phone below. Completely ignoring the desktop images.

  const sources = [
    mobile.childImageSharp.fluid,

    {
      ...desktopSmall.childImageSharp.fluid,
      media: `(min-width: 950px)`,
    },
    {
      ...desktop.childImageSharp.fluid,
      media: `(min-width: 1200px)`,
    },
    {
      ...tablet.childImageSharp.fluid,
      media: `(min-width: 500px)`,
    },
  ];

When switching the order in the array, images renders as following:
Mobile > Tablet > desktopSmall

But now it doesn't render the desktop image.

I would expect it to render depending on the queries specified:
Mobile > Tablet > desktopSmall > desktop

Environment

"gatsby": "^2.30.3",
"gatsby-image": "^2.9.0"

Minimal Reproduction

@HenrikDK2 HenrikDK2 added the type: bug An issue or pull request relating to a bug in Gatsby label Jan 18, 2021
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jan 18, 2021
@HenrikDK2 HenrikDK2 changed the title Art direction not working as expected. Art direction in gatsby-image not working as expected. Jan 18, 2021
@HenrikDK2 HenrikDK2 changed the title Art direction in gatsby-image not working as expected. [gatsby-image] Art direction in not working as expected. Jan 18, 2021
@LekoArts LekoArts added status: needs reproduction This issue needs a simplified reproduction of the bug for further troubleshooting. and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Jan 22, 2021
@LekoArts
Copy link
Contributor

Hi!

Sorry to hear you're running into an issue. To help us best begin debugging the underlying cause, it is incredibly helpful if you're able to create a minimal reproduction. This is a simplified example of the issue that makes it clear and obvious what the issue is and how we can begin to debug it.

If you're up for it, we'd very much appreciate if you could provide a minimal reproduction and we'll be able to take another look.

Thanks for using Gatsby! 💜

@HenrikDK2
Copy link
Author

Hi!

Sorry to hear you're running into an issue. To help us best begin debugging the underlying cause, it is incredibly helpful if you're able to create a minimal reproduction. This is a simplified example of the issue that makes it clear and obvious what the issue is and how we can begin to debug it.

If you're up for it, we'd very much appreciate if you could provide a minimal reproduction and we'll be able to take another look.

Thanks for using Gatsby! 💜

Here is a minimal reproduction: https://github.com/HenrikDK2/gatsby-image-art-direction-issue

@ascorbic
Copy link
Contributor

Hi @HenrikDK2 ,
The browser evaluates the sources from top to bottom, and uses the first one where the media query matches, and then falls-back to the img tag if none matches. It sees the tablet source first, and the (min-width: 500px) query matches (because the window is more than 500px wide), it uses that one and doesn't check the rest. Changing the order to this solves it for me:

  const sources = [
    mobile.childImageSharp.fluid,
    {
      ...desktop.childImageSharp.fluid,
      media: `(min-width: 1600px)`,
    },
    {
      ...laptop.childImageSharp.fluid,
      media: `(min-width: 1200px)`,
    },
    {
      ...tablet.childImageSharp.fluid,
      media: `(min-width: 500px)`,
    },
  ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs reproduction This issue needs a simplified reproduction of the bug for further troubleshooting. type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

No branches or pull requests

3 participants