-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Block Visibility: Add fetchpriority=auto to IMG tags in blocks with conditional viewport visibility to prevent potential erroneous high loading priority
#76302
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
Merged
westonruter
merged 4 commits into
trunk
from
add/fetchpriority-auto-img-in-block-visibility
Mar 9, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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' ); | ||
| } | ||
| } while ( $processor->next_tag() ); | ||
|
Comment on lines
+141
to
+149
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| $block_content = $processor->get_updated_html(); | ||
| } | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Question: If an image already had
fetchpriority="high"(orlow), 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.
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.
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.