-
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] Fixed image with media query are not resized #16763
Comments
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open! As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing! Thanks for being a part of the Gatsby community! 💪💜 |
@squelix - I think I'm also facing this same issue as well. I will try to create a minimal reproducible demo project, but at least wanted to comment that this issue shouldn't be stale. BTW, I think you made a typo. In your graphql query, you name your files |
facing the same issue as well |
I fixed my message, thanks :) |
Hey again! It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing! Thanks again for being part of the Gatsby community! |
Same issue for me with fixed Img. It always takes the first element in the array |
yes :/ |
@squelix did u get fixed? |
No... I don't have time to do it by myself, sorry :( |
@squelix if I understood correctly, you can try to set media-query to mobile image too.
Gatsby image use window.matchMedia to get current image. Maybe it helps |
@qramilq this worked for me! |
@LeeRob97 you are welcome) |
@qramilq I am running into a strange issue with the media queries, when I am in development mode things work fine, but as soon as I create my production build the first element in the array is always loaded in, regardless of the media query. I have to resize my window in order for things to start working correctly. |
@LeeRob97 did you tried to cleat .cache and public folders before run build? Cause I don't think, that production version makes so seriously changes instead of development version. |
I encountered this as well - the right image is loaded again when I resize the window over one of the media query boundaries... Development works fine, production suffers from the problem. |
Here is a repro: To trigger the bug, do: open chrome http://localhost:5000 and resize the window. Try reloading - the image is size weirdly until you again resize window to a point where you hit one of the media query boundaries. |
@qramilq I switched my images from type fixed to fluid and that works. |
There's definitely a bug here. Gatsby will pick a different image depending on the environment.
Would be nice if someone could have a look at it. Thanks. |
@gatsbyjs/core how is this closed when people are still having this problem nowadays? |
I'm experiencing the same problem, are we able to reopen this one? I query for my images as follows:
I set up my sources as follows:
In development this works fine, but in production the first source in that array is matched, until the screen is resized. Is it something to do with SSR? |
Exactly the same issue, works on development but not in the production build. |
Anybody willing to put up a PR to fix whatever the bug is? |
I fixed it by using directly export default function Home() {
const { mobileImage, desktopImage } = getImageSources();
return (
<div>
...
<picture>
<source media="(min-width: 480px)" srcSet={desktopImage.srcSet} />
<img
src={mobileImage.src}
srcSet={mobileImage.srcSet}
alt="home"
loading="lazy"
/>
</picture>
....
</div>
);
}
// P.S. You can also just grab src and srcSet instead of using `GatsbyImageSharpFixed` fragment
function getImageSources() {
const data = useStaticQuery(graphql`
query {
mobileImage: file(relativePath: { eq: "home.png" }) {
childImageSharp {
fixed(width: 500) {
...GatsbyImageSharpFixed
}
}
}
desktopImage: file(relativePath: { eq: "home.png" }) {
childImageSharp {
fixed(width: 900) {
...GatsbyImageSharpFixed
}
}
}
}
`);
return {
mobileImage: data.mobileImage.childImageSharp.fixed,
desktopImage: data.desktopImage.childImageSharp.fixed
};
} |
@KyleAMathews Please reopen this issue. |
This issue has been resolved with the following PR #24811 Please subscribe to that and await it being reviewed and merged. |
Reopening as there is a PR for it |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. Thanks for being a part of the Gatsby community! 💪💜 |
Not stale, awaiting feedback on how to proceed from core team. |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here. Thanks for being a part of the Gatsby community! 💪💜 |
Not stale, awaiting feedback on how to proceed from core team. |
const sources = [ { I did something like this to get it to work. I would love a mobile-first approach but this was the only way I got it to work. |
Description
I defined two fixed Image:
When my screen resized it downloads the smallest image but it doesn't resize the
gatsby-image-wrapper
:/Steps to reproduce
I define the Graphql queries like this:
Then I define the sources like this:
And I use the sources:
Expected result
What should happen?
Actual result
The size of the Image is
161px
even after the breakpoint of768px
, but id downloads the111px
Image.Environment
The text was updated successfully, but these errors were encountered: