Skip to content
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

Media & Text block should not use background image #52789

Closed
tkapler opened this issue Jul 20, 2023 · 6 comments
Closed

Media & Text block should not use background image #52789

tkapler opened this issue Jul 20, 2023 · 6 comments
Labels
[Block] Media & Text Affects the Media & Text Block [Feature] Media Anything that impacts the experience of managing media [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement. [Type] Performance Related to performance efforts

Comments

@tkapler
Copy link

tkapler commented Jul 20, 2023

What problem does this address?

Current image+text block uses css background image for the image. The problem is, that this way it is not possible to use loading of the images (https://web.dev/browser-level-image-lazy-loading/#can-css-background-images-take-advantage-of-the-loading-attribute) and so it highly affects the initial page loading and Google LCP metrics https://web.dev/lcp/#what-elements-are-considered

What is your proposed solution?

I believe the same visual functionality can be achieved today with CSS grid/flex and CSS object-fit property

and BTW it would be great if all the image/gallery blocks would have lazy loading true/false property to set (with some option for the defaults).

@t-hamano
Copy link
Contributor

Hi @tkapler,

Thanks for the report.

Are you referring to Media & Text block? If so, the image is rendered as an img tag.

image

@t-hamano t-hamano added the [Status] Needs More Info Follow-up required in order to be actionable. label Jul 20, 2023
@stokesman
Copy link
Contributor

Media & Text has the setting "Crop image to fill entire column". When it's on, the img tag is visually hidden and the figure gets a background image applied. I agree with @tkapler, this ought to be updated to use object-fit on the img instead.

@t-hamano
Copy link
Contributor

I see, I had missed that 😅

The Meda & Text block has a Focal Point Picker, but I think it can be handled by object-fit and object-position, just as the Cover block is so implemented.

@t-hamano t-hamano added [Type] Enhancement A suggestion for improvement. [Block] Media & Text Affects the Media & Text Block and removed [Status] Needs More Info Follow-up required in order to be actionable. labels Jul 21, 2023
@stokesman stokesman changed the title Image+Text block should not use background image Media & Text block should not use background image Jul 29, 2023
@stokesman stokesman added [Block] Media & Text Affects the Media & Text Block and removed [Block] Media & Text Affects the Media & Text Block labels Jul 29, 2023
@joemcgill joemcgill added [Feature] Media Anything that impacts the experience of managing media [Type] Performance Related to performance efforts labels Nov 27, 2023
@joemcgill
Copy link
Member

Additionally, when a background image is used, the original img element is still in the DOM, but is hidden using CSS, which can lead to two different files being loaded depending on how the srcset and sizes attributes on the hidden image are configured. See: https://github.com/WordPress/gutenberg/blob/wp/6.4/packages/block-library/src/media-text/style.scss#L89-L99

@nicomollet
Copy link

I added a PR two months ago, can someone take at look at it?

@sgomes
Copy link
Contributor

sgomes commented Sep 4, 2024

This was fixed in #64981, now in trunk. Old markup should still work correctly using background-image, but new markup will use object-fit instead. Editing old markup should upgrade it to new markup automatically, as you're used to with other blocks that have gone through deprecations.

Please let me know if you come across any bugs!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Media & Text Affects the Media & Text Block [Feature] Media Anything that impacts the experience of managing media [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement. [Type] Performance Related to performance efforts
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants