-
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
Image Block: Use CSS style width/height instead of attributes #51929
Comments
Functionally, there should be no difference between width/height set using attributes and CSS, and I can't replicate this behavior. Can you post a snippet of HTML that can be pasted into the editor and demonstrates this problem? |
@cbirdsong I updated the description with a code snippet and some screenshots. It was a bug that I introduced, and I'm working on a fix for it now. |
@ajlende @cbirdsong Images without See also https://web.dev/optimize-cls/#images-without-dimensions |
Having a Removing the attributes is mostly for efficiency and shipping less HTML. I expect it would still work fine with the attributes and the CSS, but the CSS should be enough on its own.
I can't add them to the figure because the image block includes a caption inside the figure that shouldn't be included in the aspect ratio calculation. Whereas, the featured image block has a wrapper with only the image inside, so it can be applied to the wrapper. I'm out this week, so I won't be making any progress until I'm back. I've pushed some things up to #52220 that I'll continue working on when I return. |
Is this change conditional and only applied when you modify the aspect ratio, or is it applied univerally? Using inline CSS instead of HTML attributes is unnecessary for 99% of cases, and the addition of inline CSS is a major problem if you want to use a strict content security policy that doesn't include |
@cbirdsong I think it's applied in all cases, but note that the CSS isn't instead of the HTML attributes, it is as well as them. Is that still an issue? |
@cbirdsong There are lots of places where inline CSS is used within Gutenberg—we have an entire Would generating a stylesheet with classnames for these styles work around the CSP? I worked on a system for generating stylesheets for a different feature, and I wonder if that might be needed for all of these places that use inline CSS if the CSP is that big of a problem. |
Yeah, if it's supplementary that should be fine. Shipping duplicated info like that isn't optimal, but that's preferable to it not working if CSS is disabled for whatever reason.
Yes, making an issue detailing the problems we've run into and workarounds we've had to employ to use a CSP has been on my to-do list for a while. For this issue I wanted to make sure an extremely fundamental thing like image sizing was not going to move to relying exclusively on inline CSS.
This would definitely be a good solution, and it would probably also help with making each page's CSS cacheable! |
Since these are per-block customization, I don't think it would be very cacheable, but we would be able to prevent some unused CSS from ever needing to be loaded on the page. |
Description
The
width
andheight
<img>
attributes don't work well withobject-fit
CSS. The image block needs to be updated to use CSSwidth
andheight
instead. This can be added in thestyle
attribute so it can have the same effect of holding space on the page when the attributes are set.Step-by-step reproduction instructions
Screenshots, screen recording, code snippet
In this example, the image should be square on the frontend with the content filling the entire space (
object-fit: cover
), but it does not respect the set width and height.Environment info
Reproduced in both latest Firefox and Chromium.
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: