-
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
Add srcset for cover image #25171
Add srcset for cover image #25171
Conversation
@ajlende Thanks so much for doing the work on this! I'm really excited, and hope this gets folded in for WP 5.6. In addition to the performance benefits of |
80480db
to
d5521e9
Compare
gutenberg_register_vendor_script( | ||
$scripts, | ||
'object-fit-polyfill', | ||
'https://unpkg.com/objectFitPolyfill@2.3.0/dist/objectFitPolyfill.min.js', |
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.
We should not be using CDNs like unpkg.
Historically WordPress bundles whatever it needs, but in this case I'm not sure what would be best to do. This is a polyfill for IE only since other browsers natively support object-fit, so perhaps this should be left out?
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.
Yeah, I wasn't 100% certain the best way to go about it.
@aduth might have some insight. Looks like he's done some things with polyfills.
The file doesn't actually get loaded from the CDN in the bundle. get-vendor-scripts.php downloads them for the bundle.
And the way this is set up, the script will only be loaded in browsers that fail the test ("objectFit" in document.documentElement.style
). I confirmed that it loads in IE, but not in Firefox or Chrome.
An alternative might be to just use the transform: translate(-50%, -50%); top: 50%; left: 50%
trick; although, that would break object-position
in IE.
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 file doesn't actually get loaded from the CDN in the bundle. get-vendor-scripts.php downloads them for the bundle.
I didn't know that, pretty cool! 👍
To be honest, IE users can't (and don't) expect things to work the same way they'd work on other browsers. The fact that WP still supports IE11 doesn't necessarily mean that things should be identical. As long as IE users can see and consume the content, some visual inconsistencies are to be expected. That is why global-styles use CSS variables too...
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.
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.
@noisysocks was this polyfill backported to Core somehow?
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.
Nevermind, I just found it :)
Awesome work @ajlende! Looking forward to this landing, it will lead to a huge performance boost for my sites <3 |
Conflicts: lib/client-assets.php
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 looks good and tested well for me. I tried with an existing cover block and saw no problems before and after the PR applied. The srcset shows fine, and no block breakage or issues.
As far as polyfill, if it just gets bundled in build, I don't see that as a problem. I agree with @aristath that it is fine to limit the functionality for IE11 as along as nothing is completely broken, if the experience is not optimal or slightly different is ok, just not broken.
Good work on this, thanks for sticking with it 👍
@ajlende big thanks for handling this and keeping it updated! This is going to make a huge performance impact on my sites. |
Great work on this @ajlende! There are a couple of things I'm seeing since this was merged. One should be an easy fix and I don't know about the other. Repeated backgrounds aren't working. That feature #26001 came along after this PR was made but got merged before it. I remember seeing it discussed #25421 (comment) that setting the Cover to have a fixed background is an exception to the The other thing is that most of the preexisting Cover blocks I tested this with updated successfully. I found one that didn't. Maybe because it had padding applied (from the spacing/padding block supports). If that is the cause, I don't know if that can be accounted for in the upgrade logic or if it should be (is spacing support still experimental?) If it helps, this was the invalidation errror:
|
@stokesman Where are you getting the spacing/padding block supports, a plugin? I didn't see any settings for changing that when I was testing on the master branch. If it's a plugin, I don't think there's much that I can do, but you can still send me the link and I can take a look just in case. |
In the theme I was testing it is enabled via experimental-theme.json. The content from my theme's file pared-down to the relevant bits{
"global": {
"settings": {
"spacing": {
"customPadding": true,
"units": [
"%",
"px"
]
}
}
}
} I guess it also can be enabled with a bit of PHP Apparently, it's stable since #25788. |
I've made more tests of upgrades on various Cover blocks. I'm finding that when a custom color has been used for the overlay, after the upgrade, the custom color shows in the settings sidebar but not in the block. Here's what I see: cover-srcset-custom-color.mp4Works fine with colors from the palette or gradients (custom or from palette). |
Regarding my last comment, it actually applies to newly created cover blocks too (not just upgraded ones). Using a custom color is apparently being saved in the block attributes and does show up in the frontend. In the editor, it does as shown in the recording. |
I'm also seeing a similar bug with the image not reappearing on refresh. img-bug.mp4EDIT: Not sure if that or the color are related to this PR, but I'm investigating. |
edit: Never mind! It's dual ISC / MIT. Just didn't have a LICENSE file so I missed it 🙂 https://github.com/constancecchen/object-fit-polyfill/blob/0a59e20c327c8b7984df3eaf852537656e3ada1c/package.json#L20 |
edit: Glad that's okay! |
@noisysocks here's the PR for uploading the unminified version if you wanted to keep an eye on it: cee-chen/object-fit-polyfill#59 |
uugh this is why i hate using wordpress |
Description
Fixes #17463
Additionally, this will help me with Automattic/block-experiments#143. With the image as a separate DOM Element, it'll be possible to create Block Filters that modify the appearance of the image.
data-object-fit
attribute needs to be added to the element HTML, but it was the simplest polyfill that supportedobject-position
)(or apply fallback CSS with@supports
Gallery block not "Cropping" images not working on Internet Explorer and Edge 15 #17775 (comment))How has this been tested?
Types of changes
New feature? Breaking change?
Checklist: