Skip to content

Commit da82b2e

Browse files
committed
Add fetchpriority=low to IMG tags in collapsed Accordion Item blocks (#76336)
* Add fetchpriority=low to IMG tags in collapsed Accordion Item blocks * Remove removal of loading attribute since handled by WordPress/wordpress-develop#11196 Co-authored-by: westonruter <westonruter@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: im3dabasia <im3dabasia1@git.wordpress.org> Source: WordPress/gutenberg@947d78a
1 parent ff82d05 commit da82b2e

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ This is a duplicate of the [WordPress/Gutenberg](https://github.com/WordPress/gu
55
You are currently viewing the version build from the source:
66

77
* Branch: `wp/7.0`
8-
* Commit: [WordPress/Gutenberg@`b9de6ed278b`](https://github.com/WordPress/gutenberg/commit/b9de6ed278b5eafd2f3f2fb0e72221dbddd0dd03), [Browse files](https://github.com/WordPress/gutenberg/tree/b9de6ed278b5eafd2f3f2fb0e72221dbddd0dd03)
8+
* Commit: [WordPress/Gutenberg@`947d78aa261`](https://github.com/WordPress/gutenberg/commit/947d78aa2619458ad5223d92e2b0480fc42821d9), [Browse files](https://github.com/WordPress/gutenberg/tree/947d78aa2619458ad5223d92e2b0480fc42821d9)
99

1010
> [!NOTE]
1111
> This readme file has replaced the original version included in the upstream repository.
1212
>
13-
> The [original `README.md` file](https://github.com/WordPress/gutenberg/blob/b9de6ed278b5eafd2f3f2fb0e72221dbddd0dd03/README.md) file for this commit can be found in the upstream repository.
13+
> The [original `README.md` file](https://github.com/WordPress/gutenberg/blob/947d78aa2619458ad5223d92e2b0480fc42821d9/README.md) file for this commit can be found in the upstream repository.
1414
1515
## Pupose
1616

build/scripts/block-library/accordion-item.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
* @package WordPress
77
* @since 6.9.0
88
*
9-
* @param array $attributes The block attributes.
10-
* @param string $content The block content.
11-
*
9+
* @param array{ openByDefault: bool } $attributes The block attributes.
10+
* @param string $content The block content.
1211
* @return string Returns the updated markup.
1312
*/
14-
function gutenberg_block_core_accordion_item_render( $attributes, $content ) {
15-
if ( ! $content ) {
13+
function gutenberg_block_core_accordion_item_render( array $attributes, string $content ): string {
14+
if ( '' === $content ) {
1615
return $content;
1716
}
1817

@@ -56,6 +55,19 @@ function gutenberg_block_core_accordion_item_render( $attributes, $content ) {
5655
}
5756
}
5857

58+
/*
59+
* If an Accordion Item is collapsed by default, ensure any contained IMG has fetchpriority=low to deprioritize it
60+
* from contending with resources in the critical rendering path. In contrast, remove the loading attribute to
61+
* prevent the image from not being available when the item is expanded.
62+
*/
63+
if ( ! $attributes['openByDefault'] ) {
64+
$processor = new WP_HTML_Tag_Processor( $content );
65+
while ( $processor->next_tag( 'IMG' ) ) {
66+
$processor->set_attribute( 'fetchpriority', 'low' );
67+
}
68+
$content = $processor->get_updated_html();
69+
}
70+
5971
return $content;
6072
}
6173

0 commit comments

Comments
 (0)