-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Fix - Image block: Aspect ratio not responding when dimensions are not set. #66217
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +30 B (0%) Total Size: 1.77 MB
ℹ️ View Unchanged
|
@juanfra are you able to reproduce the issue with any other image apart from the one in that pattern? I tried with another rectangular image in an image block, both on its own and inside a Grid block, and I can't reproduce it. Is there something about that specific image that is causing the bug? |
@talldan if you're using the image block to add these other images you're testing with, you shouldn't be able to reproduce as the image block will set the dimensions for the image. The problem should be happening with images that don't have a width/height set, which will likely occur with patterns including images. |
I think that was meant for @tellthemachines |
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.
The fix works as described but I'm lacking some context about aspect ratios and images.
I think perhaps @ajlende has some expertise here and may be able to offer insight.
Yes, sorry. I accepted the autocomplete too early. |
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 tested a few scenarios with combinations of width and height constrained containers, and they all seemed fine. So this looks good to me.
When would an image ever not be in an Image block though? Do you have some steps for reproduction? |
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.
When would an image ever not be in an Image block though? Do you have some steps for reproduction?
One scenario where there's an image that isn't an Image block is within the Media and Text block.
That said, I don't believe the issue here is with using, or not using, the image block. That was a red herring 🙂
Here's what I found while testing:
- The pattern in question in the PR description actually uses Image blocks
- As the images for the blocks in the pattern aren't uploaded to the media library, the width/height dimensions aren't known so those attributes aren't set on the
img
element when rendering on the frontend - This issue can be tested in the editor using an image block if you use "insert from URL" rather than one from the media library
- The problem only exists on the frontend with Firefox
Simplest steps to replicate in Firefox:
- Add an image block to a post
- Insert portrait image from url
- Apply square aspect ratio and save
- View post on the frontend.
Before this PR the image will still have a portrait aspect ratio. After, the square aspect ratio is applied.
I'm not super familiar with the inner workings of the aspect ratio feature but if @ajlende is happy with it, it gets my vote too.
✅ The new style didn't appear to negatively impact other images or rendering in other browsers
✅ This PR fixed the aspect ratio issue on the frontend in Firefox
✅ Didn't spot any issues testing different sizes, aspect ratios, and container restrictions
Before | After |
---|---|
Sorry, I wasn't clear. I meant when images were not added using the image block and in the media library (via clicking items in the UI). Not that the markup wasn't using the image block. This should happen in any scenario where the image doesn't have width and/or height. There are steps for reproduction on the issue here.
Thanks, this is what I meant. Sorry for the confusion. The issue was discovered while developing Twenty Twenty-Five. So, it's pretty likely that people developing their patterns (with local images and aspect ratio set) will have the same problem. |
@juanfra This is labelled as |
@getdave I believe the problem was always there. It was probably discovered now as it's an edge case. Given that it's affecting at least one pattern of Twenty Twenty-Five, I'd love if it could get included in 6.7 RC2. And yes, it's probably a bug rather than an enhancement. |
I just cherry-picked this PR to the wp/6.7 branch to get it included in the next release: f73c2cc |
@juanfra After this commit, SVG images are no longer displayed. |
@EldarAgalarov thanks for sharing. Can you please include precise steps to replicate that? I believe it would be best if you can create an issue with clear instructions on how to reproduce. |
|
@EldarAgalarov I can't replicate. Please see the screencast: Screen.Recording.2024-10-31.at.16.15.39.movI'm on Mac, WP RC2, and I tried in Chrome, Safari, and Firefox. I had to add a custom snippet to allow the upload of SVG files as they're not allowed by default. |
@juanfra I tested with the same image and it works, because this image have width and height attributes. Try to test SVG image with viewBox and without width and height attributes. |
@EldarAgalarov can you please share the image that you're trying with here? |
@juanfra An example of responsive SVG: |
@EldarAgalarov thanks for sharing. I've created a PR to address this issue here. |
@juanfra Similar to SVG, this is causing a bug with images that use |
…ms in Firefox. (#66217)" (#66804) Co-authored-by: kevin940726 <[email protected]> Co-authored-by: ramonjd <[email protected]> Co-authored-by: mukeshpanchal27 <[email protected]> Co-authored-by: juanfra <[email protected]> This reverts commit 0e65adc.
…ms in Firefox. (#66217)" (#66804) Co-authored-by: kevin940726 <[email protected]> Co-authored-by: ramonjd <[email protected]> Co-authored-by: mukeshpanchal27 <[email protected]> Co-authored-by: juanfra <[email protected]> This reverts commit 0e65adc.
Thank you, looks like we need an alternative solution to this. |
…ms in Firefox. (WordPress#66217)" (WordPress#66804) Co-authored-by: kevin940726 <[email protected]> Co-authored-by: ramonjd <[email protected]> Co-authored-by: mukeshpanchal27 <[email protected]> Co-authored-by: juanfra <[email protected]> This reverts commit 0e65adc.
…ms in Firefox. (#66217)" (#66804) Co-authored-by: kevin940726 <[email protected]> Co-authored-by: ramonjd <[email protected]> Co-authored-by: mukeshpanchal27 <[email protected]> Co-authored-by: juanfra <[email protected]> This reverts commit 0e65adc.
What?
Fixes #66175
Set image width to
fit-content
to solve aspect ratio problems in Firefox.Why?
For the aspect ratio to work, at least in Firefox, the image's width must be set. If not, the aspect ratio doesn't work.
How?
Setting the image width to
fit-content
so that it has a default.Testing Instructions
Screenshots or screencast
Screen.Recording.2024-10-17.at.18.23.39.mov