-
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: Set the fit-content
width for images that are not .svg
#66643
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: +79 B (0%) Total Size: 1.81 MB
ℹ️ View Unchanged
|
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.
Thanks for the follow-up @juanfra 👍
This is testing well for me. I also like that the conditional nature of the styling is confined to the CSS.
✅ Could replicate the issue in Firefox
✅ This PR fixes the problem in Firefox
✅ Fix from #66217 has been maintained
✅ Didn't spot any further regressions in other browsers
Added the |
@@ -9,7 +9,10 @@ | |||
max-width: 100%; | |||
vertical-align: bottom; | |||
box-sizing: border-box; | |||
width: fit-content; | |||
|
|||
&:not([src$=".svg"]) { |
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.
Can we be certain that svg files always have .svg
at the end of their sources in WP?
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.
@kevin940726 I believe in the context of the image block, yes. I was researching, and the other option is the .svgz
extension, which is for compressed SVGs. I never saw any, but we could add it, to make it more robust and cover all cases.
&:not([src$=".svg"]) { | |
&:not([src$=".svg"]):not([src$=".svgz"]) { |
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'm mostly concerned that SVG files don't have to end with the .svg
postfix in the URLs. Browsers look for the content types, not the file extensions. I'm not sure if this applies to this case though!
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 guess it's not certain but highly likely. So if this fixes for 80% of sites then it's an improvement.
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'm mostly concerned that SVG files don't have to end with the .svg postfix in the URLs. Browsers look for the content types, not the file extensions. I'm not sure if this applies to this case though!
This is true, but I believe it doesn't apply to this case, where the SVG is uploaded via UI and inserted via image block. If I'm not mistaken, the media library/image block should insert images with their file extensions.
The problem would be if a block themer, includes an image block on some pattern or template, where the image src uses data:image/...
, and if the image doesn't have dimensions.
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.
First of all, I agree! I think this is a good improvement even though I have some minor concerns. I think we can merge this and iterate if necessary.
If I'm not mistaken, the media library/image block should insert images with their file extensions.
Would someone be able to insert an SVG file via an external URL? I'm not too familiar with the media upload module, but could someone upload an SVG file without the extension? That is, does the code look for the MIME type or the file extension?
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.
Would someone be able to insert an SVG file via an external URL? I'm not too familiar with the media upload module, but could someone upload an SVG file without the extension?
As far as I know, not via UI using the medialibrary.
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 this and it fixes the issue for any image with the .svg
extension which should cover 80% of the use cases.
There may be an outstanding issues with mime-types and file extensions not matching but that is likely an edge case.
I think we should merge and bring this into 6.7.
Co-authored-by: juanfra <juanfra@git.wordpress.org> Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org> Co-authored-by: kevin940726 <kevin940726@git.wordpress.org> Co-authored-by: getdave <get_dave@git.wordpress.org>
I just cherry-picked this PR to the wp/6.7 branch to get it included in the next release: 26d154b |
Thanks! |
…#66643) Co-authored-by: juanfra <juanfra@git.wordpress.org> Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org> Co-authored-by: kevin940726 <kevin940726@git.wordpress.org> Co-authored-by: getdave <get_dave@git.wordpress.org>
What?
This is a follow-up of #66217
In this comment reported that the fix from #66217 was preventing responsive svg images to display.
Why?
So that we don't have a regression with SVG images as they're widely used.
How?
The fix is now being applied to all images that are not SVGs.
Testing Instructions
Screenshots or screencast
Screen.Recording.2024-10-31.at.16.56.12.mov