-
Notifications
You must be signed in to change notification settings - Fork 687
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
#2333 Add optional ratio for ressources #2372
Conversation
Sweet! I remember a short convo with Tommy saying he didn't like the explicit "ratio={1/2}" API. Not sure why, but maybe @tjwiebell could elaborate it a bit more ? |
|
To really test this scenario you should change the story test case to
Now what's going to happen is that the @tjwiebell this is the issue I addressed in the meeting. |
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.
Hey, @larsroettig thanks for working on this. I have a couple of changes for you. Minor aesthetics nothing major.
Co-authored-by: Revanth Kumar Annavarapu <35203638+revanth0212@users.noreply.github.com>
Performance Test Results The following fails have been reported by WebpageTest. These numbers indicates a possible performance issue with the PR which requires further manual testing to validate. https://pr-2372.pwa-venia.com : LH Performance Expected 0.85 Actual 0.58, LH Best Practices Expected 1 Actual 0.92 |
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.
ResourceImage works perfect 👍 but need to account for some additional use cases. While stepping through, I also wanted to confirm an assumption I had that didn't quite work.
I assumed as an SI, if I was using a different aspect ratio for all of my images, I could change the value of DEFAULT_WIDTH_TO_HEIGHT_RATIO
, and that would propagate throughout the app; but it didn't. Since @revanth0212 is the subject expert, I just wanted to confirm; if that constant isn't driving the aspect ratio of images in Venia, what is?
@@ -45,6 +46,7 @@ const Image = props => { | |||
type, | |||
width, | |||
widths, | |||
ratio, |
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.
I would expect that ratio should also work with the SimpleImage
component as well. I don't want to get into a huge rabbit hole re-factor, but the useImage
talon seems like the best place to have this logic; if height isn't provided but ratio is, calculate height and drill that down.
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.
I haven't thought of that use case. Is it possible? Neverthless, it is good to have a check. Done. Nice suggestion @tjwiebell. Fixed in 5536d61
if (!imageURL || !type) return ''; | ||
|
||
const imageRatio = ratio || DEFAULT_WIDTH_TO_HEIGHT_RATIO; |
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.
This API would need to change, so maybe drilling ratio is still best to keep things simple.
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.
I have made sure to add default props for the ratio in the components that end up using this util.
packages/venia-ui/lib/util/images.js
Outdated
@@ -57,17 +57,18 @@ export const generateUrlFromContainerWidth = ( | |||
); |
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.
Why isn't the line above also taking ratio into account?
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.
Nice question. No reason not to have it. Fixed in b5126ab.
Note: I have not gone into the useProductImageCarousel
talon, ProductImageCarousel
component, and the components using this component to make the change of sending it as a prop. Felt out of scope for this PR. If someone wants to change this, they can send it as a prop and then as an argument to this function, if not the function uses the default ratio.
@@ -21,16 +22,17 @@ export const useResourceImage = props => { | |||
resource, | |||
type, | |||
width, | |||
widths | |||
widths, | |||
ratio | |||
} = props; | |||
|
|||
const src = useMemo(() => { | |||
return generateUrl(resource, type)(width, height); |
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.
Ratio should also be accounted for here. Some browsers load src and srcset side by side, and could cause the container to be the wrong size (without the right ratio).
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.
Because, after this commit 5536d61, the height sent to ResourceImage
and then to useResourceImage
is checked against the ratio. I don't think we will need this any more.
Hey guys, just wanna make sure the issue I point out isn't forgotten. Maybe I misinterpret the image helper, if so you can ignore this comment. |
Added the story in 791c526 @Jordaneisenburger is this the expected result? |
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.
Looks good 👍 we should still confirm with @Jordaneisenburger that we've solved that edge case with the imageWidths
Map.
@@ -108,7 +108,7 @@ const Image = props => { | |||
alt={alt} | |||
classes={classes} | |||
displayPlaceholder={displayPlaceholder} | |||
height={talonResourceHeight} | |||
height={height} |
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.
Not setting the calculate talon height on the image because this will override the srcset
on the img
tag. srcset
works best with width. By providing height we are making the container have a fixed height and because of that, the image stretches. In this example, the width of the image was 640px so using the ratio 4/5 the height turned out to be 800px. But the srcset
calculated width by the browser is 375px but since we are setting 800 as height, the image was being stretched.
Regression looks good on image load w/o fastly image opt auto/onboard/backend. Good to merge once review approved and @Jordaneisenburger confirms on the fix. |
Description
As a developer I'd love to re-use the
<Image/>
component for all custom components that render images. Unfortunately that's not ideal since images produced by the<Image/>
component are always in a 4:5 ratio meaning that a banner image that needs to be 16:9 won't work properly.Related Issue
Closes #2333.
Acceptance
I'd like to see a solution where the implementation decides what ratio the image needs to be instead of the internal image logic forcing it to use a set ratio. Something like this would be sufficient:
<Image ratio={4/3} />
Verification Steps
-> should display a 16 / Image
Screenshots / Screen Captures (if appropriate)
Checklist