Skip to content
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

Skip visiting tags in the Admin Bar when optimizing a page #1816

Merged
merged 5 commits into from
Jan 23, 2025

Conversation

westonruter
Copy link
Member

@westonruter westonruter commented Jan 21, 2025

Summary

Fixes #1806

Relevant technical choices

A new private OD_HTML_Tag_Processor::is_admin_bar() is introduced which returns whether the processor is currently at or inside the Admin Bar. This is used in the ::next_tag() method to ensure that it never lands on a tag that is in the Admin Bar.

@westonruter westonruter added [Type] Enhancement A suggestion for improvement of an existing feature [Plugin] Optimization Detective Issues for the Optimization Detective plugin labels Jan 21, 2025
@westonruter westonruter changed the title Skip visiting the admin bar when optimizing a page Skip visiting tags in the Admin Bar when optimizing a page Jan 21, 2025
Copy link

codecov bot commented Jan 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 65.47%. Comparing base (b9154cc) to head (8bc847c).
Report is 6 commits behind head on trunk.

Additional details and impacted files
@@            Coverage Diff             @@
##            trunk    #1816      +/-   ##
==========================================
+ Coverage   65.42%   65.47%   +0.05%     
==========================================
  Files          85       85              
  Lines        6738     6748      +10     
==========================================
+ Hits         4408     4418      +10     
  Misses       2330     2330              
Flag Coverage Δ
multisite 65.47% <100.00%> (+0.05%) ⬆️
single 37.87% <0.00%> (-0.06%) ⬇️

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.

@westonruter westonruter marked this pull request as ready for review January 22, 2025 23:27
Copy link

github-actions bot commented Jan 22, 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 <[email protected]>
Co-authored-by: felixarntz <[email protected]>
Co-authored-by: swissspidy <[email protected]>

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

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 looks good functionally, just one suggestion on where it's implemented.

Comment on lines 236 to 239
// Elements in the Admin Bar are not relevant for optimization, so skip passing them to tag visitors.
if ( $processor->is_admin_bar() ) {
continue;
}
Copy link
Member

Choose a reason for hiding this comment

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

Instead of calling this here, could this be baked into the tag processor class itself? For instance, as long as we're in the admin bar, the tag processor could move on to the next element.

I think that would be better for ergonomics, as it would handle the issue in one place and would avoid having to introduce a public method for something as specific as this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I think that makes sense. See 8373c35.

Base automatically changed from add/od-xpath-body-children-disambiguation to trunk January 23, 2025 00:08
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 LGTM, though there is a merge conflict now, could you address it?

@westonruter westonruter merged commit b7c4475 into trunk Jan 23, 2025
15 checks passed
@westonruter westonruter deleted the add/admin-bar-skipping branch January 23, 2025 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Optimization Detective Issues for the Optimization Detective plugin [Type] Enhancement A suggestion for improvement of an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should elements in the Admin Bar be excluded from processing by Optimization Detective?
2 participants