From 0c23fc3cd298f9e1812684522bdaac7f49133725 Mon Sep 17 00:00:00 2001 From: theaminuldev Date: Thu, 27 Nov 2025 08:03:36 +0600 Subject: [PATCH 1/4] Handle empty href in blocking assets audit Updated the check for the href attribute in perflab_aea_audit_blocking_assets to skip processing when href is an empty string, preventing potential issues with invalid asset URLs. --- .../includes/site-health/audit-enqueued-assets/helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/performance-lab/includes/site-health/audit-enqueued-assets/helper.php b/plugins/performance-lab/includes/site-health/audit-enqueued-assets/helper.php index 7b54647779..b858f169c6 100644 --- a/plugins/performance-lab/includes/site-health/audit-enqueued-assets/helper.php +++ b/plugins/performance-lab/includes/site-health/audit-enqueued-assets/helper.php @@ -119,7 +119,7 @@ function perflab_aea_audit_blocking_assets(): array { } $href = $processor->get_attribute( 'href' ); - if ( ! is_string( $href ) ) { + if ( ! is_string( $href ) || '' === $href ) { continue; } From e41bf617d990bcd40a57f7b5f7654b0a1bb41cd6 Mon Sep 17 00:00:00 2001 From: Md Aminul Islam <56115259+theaminuli@users.noreply.github.com> Date: Thu, 27 Nov 2025 21:52:29 +0600 Subject: [PATCH 2/4] Fix: skip empty stylesheet href values in asset audit Co-authored-by: Weston Ruter --- .../includes/site-health/audit-enqueued-assets/helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/performance-lab/includes/site-health/audit-enqueued-assets/helper.php b/plugins/performance-lab/includes/site-health/audit-enqueued-assets/helper.php index b858f169c6..aeb1f7ee55 100644 --- a/plugins/performance-lab/includes/site-health/audit-enqueued-assets/helper.php +++ b/plugins/performance-lab/includes/site-health/audit-enqueued-assets/helper.php @@ -119,7 +119,7 @@ function perflab_aea_audit_blocking_assets(): array { } $href = $processor->get_attribute( 'href' ); - if ( ! is_string( $href ) || '' === $href ) { + if ( ! is_string( $href ) || '' === trim( $href ) ) { continue; } From 69985a336a12a03e17ede30c0784eec770998026 Mon Sep 17 00:00:00 2001 From: theaminuldev Date: Thu, 27 Nov 2025 22:14:33 +0600 Subject: [PATCH 3/4] Add test for enqueued style with empty href Introduces a test case to verify that styles enqueued with an empty href are handled correctly. This addresses issue #2278 and ensures that such styles are not included in the audited assets. --- .../test-audit-enqueued-assets.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/plugins/performance-lab/tests/includes/site-health/audit-enqueued-assets/test-audit-enqueued-assets.php b/plugins/performance-lab/tests/includes/site-health/audit-enqueued-assets/test-audit-enqueued-assets.php index a99501b706..0627d774ad 100644 --- a/plugins/performance-lab/tests/includes/site-health/audit-enqueued-assets/test-audit-enqueued-assets.php +++ b/plugins/performance-lab/tests/includes/site-health/audit-enqueued-assets/test-audit-enqueued-assets.php @@ -168,6 +168,11 @@ public function test_perflab_aea_audit_enqueued_styles(): void { wp_dequeue_style( 'style3' ); wp_enqueue_style( 'style-print', 'https://print-style.com', array(), null, 'print' ); wp_enqueue_style( 'style-no-href', 'https://no-href-style.com', array(), null ); + /** + * Enqueue style with empty href + * @see https://github.com/WordPress/performance/issues/2278 + */ + wp_enqueue_style( 'style-empty-href', 'https://empty-href-style.com', array(), null ); // Filter to remove href attribute from a specific style handle. add_filter( @@ -176,6 +181,14 @@ static function ( $tag, $handle ) { if ( 'style-no-href' === $handle ) { $tag = str_replace( 'href=\'https://no-href-style.com\'', ' ', $tag ); } + + if ( 'style-empty-href' === $handle ) { + $tag = str_replace( + 'href=\'https://empty-href-style.com\'', + "href=''", + $tag + ); + } return $tag; }, 10, @@ -242,6 +255,14 @@ static function ( $item ) { } ); $this->assertEmpty( $no_href_style ); + + $empty_href_style = array_filter( + $assets['styles'], + static function ( $item ) { + return 'https://empty-href-style.com' === $item['src']; + } + ); + $this->assertEmpty( $empty_href_style ); } /** From 756a8aa84763a45dacdc1b6458b841360e68b937 Mon Sep 17 00:00:00 2001 From: theaminuldev Date: Thu, 27 Nov 2025 22:24:08 +0600 Subject: [PATCH 4/4] Fix whitespace in test-audit-enqueued-assets.php Corrects whitespace in the test for enqueued assets and adds a docblock line for clarity. No functional changes to the test logic. --- .../audit-enqueued-assets/test-audit-enqueued-assets.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/performance-lab/tests/includes/site-health/audit-enqueued-assets/test-audit-enqueued-assets.php b/plugins/performance-lab/tests/includes/site-health/audit-enqueued-assets/test-audit-enqueued-assets.php index 0627d774ad..8c8a0ab4ad 100644 --- a/plugins/performance-lab/tests/includes/site-health/audit-enqueued-assets/test-audit-enqueued-assets.php +++ b/plugins/performance-lab/tests/includes/site-health/audit-enqueued-assets/test-audit-enqueued-assets.php @@ -170,6 +170,7 @@ public function test_perflab_aea_audit_enqueued_styles(): void { wp_enqueue_style( 'style-no-href', 'https://no-href-style.com', array(), null ); /** * Enqueue style with empty href + * * @see https://github.com/WordPress/performance/issues/2278 */ wp_enqueue_style( 'style-empty-href', 'https://empty-href-style.com', array(), null ); @@ -181,7 +182,7 @@ static function ( $tag, $handle ) { if ( 'style-no-href' === $handle ) { $tag = str_replace( 'href=\'https://no-href-style.com\'', ' ', $tag ); } - + if ( 'style-empty-href' === $handle ) { $tag = str_replace( 'href=\'https://empty-href-style.com\'',