Skip to content

Fix unpredictable LCP element being identified in a URL Metric Group #1903

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
merged 5 commits into from
Mar 5, 2025

Conversation

westonruter
Copy link
Member

@westonruter westonruter commented Mar 4, 2025

Summary

Fixes #1896
See #1902

Relevant technical choices

Now \OD_URL_Metric_Group::get_lcp_element() will prefer to use URL Metrics which have a current ETag. If there are none, then it falls back to using all of the stale URL Metrics. This ensures that if a URL Metric group has two URL Metrics, one with a mismatched ETag and another with an ETag that matches the current ETag, that the logic will not possibly result in the LCP element being pulled from the URL Metric with the stale ETag, which can currently happen if there are an equal number of stale and fresh URL Metrics in a group.

@westonruter westonruter added [Type] Bug An existing feature is broken [Plugin] Optimization Detective Issues for the Optimization Detective plugin [Plugin] Image Prioritizer Issues for the Image Prioritizer plugin (dependent on Optimization Detective) labels Mar 4, 2025
Copy link

codecov bot commented Mar 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.63%. Comparing base (db322a3) to head (b96df7c).
Report is 6 commits behind head on trunk.

Additional details and impacted files
@@            Coverage Diff             @@
##            trunk    #1903      +/-   ##
==========================================
+ Coverage   69.59%   69.63%   +0.03%     
==========================================
  Files          86       86              
  Lines        6983     6991       +8     
==========================================
+ Hits         4860     4868       +8     
  Misses       2123     2123              
Flag Coverage Δ
multisite 69.63% <100.00%> (+0.03%) ⬆️
single 39.57% <0.00%> (-0.05%) ⬇️

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 force-pushed the fix/unpredictable-lcp-element branch from e891fd0 to f1e39a7 Compare March 4, 2025 21:34
@westonruter westonruter marked this pull request as ready for review March 4, 2025 21:34
Copy link

github-actions bot commented Mar 4, 2025

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: westonruter <westonruter@git.wordpress.org>
Co-authored-by: felixarntz <flixos90@git.wordpress.org>

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

Comment on lines +363 to +376
// Prefer to use URL Metrics which have a current ETag.
$url_metrics = array_filter(
$this->url_metrics,
function ( OD_URL_Metric $url_metric ): bool {
return $url_metric->get_etag() === $this->get_collection()->get_current_etag();
}
);

// Otherwise, if no URL Metrics have a current ETag, fall back to using all the stale ones.
if ( count( $url_metrics ) === 0 ) {
$url_metrics = $this->url_metrics;
}

foreach ( $url_metrics as $url_metric ) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the only actual plugin code change. Everything else is for tests.

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@westonruter This mostly looks good, just two points of feedback.

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@westonruter Thanks for the updates, LGTM!

@westonruter westonruter merged commit ad006e6 into trunk Mar 5, 2025
18 checks passed
@westonruter westonruter deleted the fix/unpredictable-lcp-element branch March 5, 2025 18:40
westonruter added a commit to b1ink0/performance that referenced this pull request Mar 10, 2025
westonruter added a commit that referenced this pull request Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Image Prioritizer Issues for the Image Prioritizer plugin (dependent on Optimization Detective) [Plugin] Optimization Detective Issues for the Optimization Detective plugin [Type] Bug An existing feature is broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Common LCP element IMG not resulting in single preload LINK
2 participants