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

wp-block-post-featured-image missing the lazy attribute #41783

Closed
Mte90 opened this issue Jun 17, 2022 · 8 comments
Closed

wp-block-post-featured-image missing the lazy attribute #41783

Mte90 opened this issue Jun 17, 2022 · 8 comments
Labels
[Block] Post Featured Image Affects the Post Featured Image Block [Type] Bug An existing feature does not function as intended [Type] Performance Related to performance efforts [Type] WP Core Ticket Requires an upstream change from WordPress. Core Trac ticket should be linked.

Comments

@Mte90
Copy link

Mte90 commented Jun 17, 2022

Description

Since WP 5.5 the lazy attribute to img tags is added automatically.

Well this block doesn't have that value...

Step-by-step reproduction instructions

  1. Add that block and see the html generated

Screenshots, screen recording, code snippet

No response

Environment info

  • WP 6.0

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

@aristath
Copy link
Member

I remember seeing a discussion somewhere that featured-images should not get the lazy attribute, because usually they are above the fold, and lazy-loading them is bad for performance and the user-experience... 🤔
I can see a post on make that says the 1st image won't be lazy-loaded, could that be what's happening here? https://make.wordpress.org/core/2021/12/29/enhanced-lazy-loading-performance-in-5-9/

@Mte90
Copy link
Author

Mte90 commented Jun 17, 2022

I remember that discussion but when in a page there is more then one?

@aristath
Copy link
Member

but when in a page there is more then one?

An example would be an archive of posts, where each post has its featured image inside the query loop 😉

@carolinan carolinan added the [Block] Post Featured Image Affects the Post Featured Image Block label Jun 22, 2022
@ockham
Copy link
Contributor

ockham commented Oct 31, 2022

Potentially related Trac ticket: https://core.trac.wordpress.org/ticket/56930.

@spacedmonkey
Copy link
Member

Related: #45224

@felixarntz
Copy link
Member

@Mte90 @aristath @ockham @spacedmonkey https://core.trac.wordpress.org/ticket/56930 is primarily caused by https://core.trac.wordpress.org/ticket/55996, which is also covered in #45224 and now has a working (core) PR in WordPress/wordpress-develop#3549.

The problem here is a different one though: I'm unsure whether the original issue description is accurate - the loading="lazy" attribute is expected to not be present if the featured image appears on top of the page (specifically, the very first image that is either a featured image or part of any post content blob), while it is expected to be present on the featured image otherwise. I just tested this with the WordPress/wordpress-develop#3549 PR branch, that fixes the root problem around lazy-loading attriibutes being incorrectly applied in block themes, and with Twenty Twenty-Two: In a post where I have the featured image as the first image on the page, it still receives the loading="lazy" attribute - so that is incorrect, but it's still the opposite of what the issue description here says the problem would be.

I believe there is something we need to tweak in the core/post-featured-image block PHP implementation so that the core heuristics for whether the attribute should be added applies correctly. Will look into it.

@felixarntz felixarntz added [Type] Bug An existing feature does not function as intended and removed [Type] Enhancement A suggestion for improvement. [Block] Image Affects the Image Block labels Nov 2, 2022
@felixarntz
Copy link
Member

I found the problem here and addressed it as part of WordPress/wordpress-develop#3560: Basically, the issue with the core/post-featured-image block here is the lack of https://github.com/WordPress/wordpress-develop/pull/3560/files#diff-a9372558b4bbc50ffb4ff3b685da5c4e1ed1e2d58cf97e47c0abbfd7c58681c9R24 in that block rendering function. This is currently breaking backward compatibility (and this core feature!); the fix here is exactly the same that has already been added to the core/post-content block for the same reason.

@felixarntz felixarntz added the [Type] WP Core Ticket Requires an upstream change from WordPress. Core Trac ticket should be linked. label Nov 3, 2022
@felixarntz
Copy link
Member

Fixed via #45534.

To follow the wider-reaching WP core fix, please follow along https://core.trac.wordpress.org/ticket/56930.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Post Featured Image Affects the Post Featured Image Block [Type] Bug An existing feature does not function as intended [Type] Performance Related to performance efforts [Type] WP Core Ticket Requires an upstream change from WordPress. Core Trac ticket should be linked.
Projects
None yet
Development

No branches or pull requests

6 participants