Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backport-changelog/7.0/11196.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/11196

* https://github.com/WordPress/gutenberg/pull/76302
10 changes: 10 additions & 0 deletions lib/block-supports/block-visibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ function gutenberg_render_block_visibility_support( $block_content, $block ) {
$processor = new WP_HTML_Tag_Processor( $block_content );
if ( $processor->next_tag() ) {
$processor->add_class( implode( ' ', $class_names ) );

/*
* Set all IMG tags to be `fetchpriority=auto` so that wp_get_loading_optimization_attributes() won't add
* `fetchpriority=high` or increment the media count to affect whether subsequent IMG tags get `loading=lazy`.
*/
do {
if ( 'IMG' === $processor->get_tag() ) {
$processor->set_attribute( 'fetchpriority', 'auto' );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: If an image already had fetchpriority="high" (or low), this will overwrite it, which could be a regression for intentionally prioritized LCP images.

Even though If we set to "auto", this is still a global mutation of all images inside the block HTML.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the image intentionally had fetchpriority="high" then this still would have been wrong, correct? It is highly unlikely that the block would be intentionally adding this while also being aware that it is in a viewport-conditional block.

}
} while ( $processor->next_tag() );
Comment on lines +141 to +149

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$block_content = $processor->get_updated_html();
}
}
Expand Down
Loading