-
Notifications
You must be signed in to change notification settings - Fork 277
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
[Hydrogen React] Don't generate srcset if size is above source image dimensions #2469
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for this PR! It looks good to me, other than I don't think we need it to be a breaking change because generateSrcSet
is not exposed externally. Please change it to be a patch
change instead.
Setting to draft. The file is exported, so someone might use it. I may have a way to go around changing the |
Refactored so it's a real patch change now. |
Thanks for this excellent PR 🙏🏼 |
Hi @andershagbard. I'm trying to wrap my head around why we shouldn't generate a srcset size if the srcset we provide from a srcSetOption interval exceeds the image dimensions. Instead of removing that srcset size, would it be better to apply the max width as the last src set option and break from there? Say we use these options for srcSetOptions but the client uploaded 4 square images for a row of images in a section with: 600x, 1100x, 1100x, 1100x. The images with 1100x dimension will show 3 srcSet sizes of 300w, 700w, 1100w. However, the 1st image will only show 1 src set option of 300w. I know this is a fault from our client, but I think it would be beneficial to at least add 1 more src set option of the max potential width of the image.
The Last question I have is what is the logic behind the Image component to render srcSetOptions as x descriptors instead of w descriptors. Depending on the srcSets passed for an image, sometimes I would get 1x, 2x, 3x, srcSets instead of 300w, 700w, 1100w |
I also stated this in the PR.
We could potentially update the component to include the highest possible image with the assigned aspect. I don't see any downside to doing this.
I haven't touched this logic in this PR. But if you pass a This is because the |
Hey @andershagbard. Thanks for getting back to me. Yes, I would love to see the component include the highest possible image with the assigned aspect. But now that I think of it, it might seem silly to see 5000w if a client added a very large image. So maybe not the best option. However, I did find something interesting. I know your PR did not involve any updates around what gets rendered such as But now knowing this, along with the new image component updates, I need to rethink about the srcSetOptions I pass to get the srcset descriptors I'm expecting. |
@adrianxadamn I would limit the biggest image to the max size defined by the I think in most cases, you don't have to pass a custom |
WHY are these changes introduced?
Fixes #2456
WHAT is this pull request doing?
<Image />
from generating asrcset
image with higher dimensions than source image. This is to prevent the Shopify CDN from just using the original image uncropped.generateSrcSet
Only downside is when not using
aspectRatio
. In case the image is 750px wide, the srcset goes from 600w to 800w, and will not generate an image for 800w with 750px width. Not sure if we should still generate it?HOW to test your changes?
Tests has been added.
Checklist