Skip to content

Conversation

@theaminuli
Copy link
Member

@theaminuli theaminuli commented Nov 27, 2025

What:

Skip stylesheet link elements that have empty href attributes during the Enqueued Assets Health Check audit.

Why:

Some themes and plugins (like Mesmerize Companion) intentionally use empty href attributes with data-href attributes as a performance optimization technique to defer CSS loading. These stylesheets are non-render-blocking by design, but were being incorrectly flagged as errors ("A valid URL was not provided") in the Site Health Status, negatively impacting site scores.

How:

Added a check for empty string href values on line 121 in perflab_aea_audit_blocking_assets(). The condition now reads:

if ( ! is_string( $href ) || '' === $href ) {
    continue;
}

This skips stylesheets with href="" from being audited, similar to how async CSS with non-standard media attributes is already excluded.

Files changed:

helper.php

Fixes #2278

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.
@github-actions
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: theaminuli <theaminuldev@git.wordpress.org>
Co-authored-by: westonruter <westonruter@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@codecov
Copy link

codecov bot commented Nov 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.86%. Comparing base (f7846e4) to head (756a8aa).
⚠️ Report is 2 commits behind head on trunk.

Additional details and impacted files
@@           Coverage Diff           @@
##            trunk    #2281   +/-   ##
=======================================
  Coverage   68.86%   68.86%           
=======================================
  Files          90       90           
  Lines        7610     7610           
=======================================
  Hits         5241     5241           
  Misses       2369     2369           
Flag Coverage Δ
multisite 68.86% <100.00%> (ø)
single 35.47% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@westonruter westonruter added this to the performance-lab n.e.x.t milestone Nov 27, 2025
@westonruter westonruter added [Type] Bug An existing feature is broken [Plugin] Performance Lab Issue relates to work in the Performance Lab Plugin only labels Nov 27, 2025
@westonruter
Copy link
Member

Thank you for the PR. Let's also update the unit test to add an assertion for this change.

theaminuli and others added 2 commits November 27, 2025 21:52
Co-authored-by: Weston Ruter <westonruter@gmail.com>
Introduces a test case to verify that styles enqueued with an empty href are handled correctly. This addresses issue WordPress#2278 and ensures that such styles are not included in the audited assets.
@theaminuli
Copy link
Member Author

theaminuli commented Nov 27, 2025

Test Added

I've added test coverage for the empty href attribute fix in the test_perflab_aea_audit_enqueued_styles() test method.

What the test does:

  • Enqueues a stylesheet with style-empty-href handle
  • Verifies that this stylesheet is properly skipped from the audit and doesn't appear in the results

Test assertion:

$empty_href_style = array_filter(
	$assets['styles'],
	static function ( $item ) {
		return 'https://empty-href-style.com' === $item['src'];
	}
);
$this->assertEmpty( $empty_href_style );

This ensures that themes/plugins using performance optimization techniques with href="" won't trigger false positives in Site Health checks.

Thanks to @westonruter for the valuable feedback on implementing this test case!

Files changed:

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Plugin] Performance Lab Issue relates to work in the Performance Lab Plugin only [Type] Bug An existing feature is broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enqueued Assets Site Health test not fully accounting for async CSS

2 participants