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

Add support for Speculative Loading WP Core API, loading the plugin's own API implementation conditionally #1883

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

felixarntz
Copy link
Member

@felixarntz felixarntz commented Feb 24, 2025

Summary

Following the WordPress Core merge of speculative loading last week, this PR ensures the Speculative Loading plugin uses the WP Core API when available, and only loads its own API implementation if not.

Relevant technical choices

  • Split code paths between one file for the plugin API and another one for the WP Core API integration.
  • Load these files conditionally, one or the other (for the plugin API, this also includes the PLSR_URL_Pattern_Prefixer class), and only add the relevant hooks.
  • For PHPUnit, all files are still unconditionally loaded to keep all code tested. The only thing that is conditional in tests is which hooks are added, which is the only real differentiator for which implementation is used.

The fact that WP Core trunk tests pass with this is a good indicator this works as expected. Also check in the PHPUnit test run using trunk on GitHub Actions that for Speculative Loading (50 tests) it makes 1 assertion more than for the other WordPress versions (104 instead of 103) because of the one additional hook checked.

… on API implementation conditionally while maintaining compatibility on plugin-specific filters.
@felixarntz felixarntz added [Type] Enhancement A suggestion for improvement of an existing feature [Plugin] Speculative Loading Issues for the Speculative Loading plugin (formerly Speculation Rules) labels Feb 24, 2025
@felixarntz felixarntz added this to the speculation-rules n.e.x.t milestone Feb 24, 2025
Copy link

github-actions bot commented Feb 24, 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.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @Yedfree.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

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

Unlinked contributors: Yedfree.

Co-authored-by: felixarntz <[email protected]>
Co-authored-by: joemcgill <[email protected]>

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

*
* @since 1.0.0
*/
function plsr_print_speculation_rules(): void {
Copy link
Member Author

Choose a reason for hiding this comment

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

Note for reviewers: This function was moved without any changes to the plugin-api.php file.

/**
* @covers ::plsr_print_speculation_rules
*/
public function test_plsr_print_speculation_rules_without_html5_support(): void {
Copy link
Member Author

Choose a reason for hiding this comment

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

Note for reviewers: These tests for the plsr_print_speculation_rules() function were moved to test-speculation-rules-plugin-api.php without any changes.

Copy link

codecov bot commented Feb 25, 2025

Codecov Report

Attention: Patch coverage is 75.00000% with 7 lines in your changes missing coverage. Please review.

Project coverage is 66.79%. Comparing base (5693cc4) to head (08ae13e).

Files with missing lines Patch % Lines
plugins/speculation-rules/hooks.php 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            trunk    #1883      +/-   ##
==========================================
+ Coverage   66.70%   66.79%   +0.08%     
==========================================
  Files          88       89       +1     
  Lines        7029     7044      +15     
==========================================
+ Hits         4689     4705      +16     
+ Misses       2340     2339       -1     
Flag Coverage Δ
multisite 66.79% <75.00%> (+0.08%) ⬆️
single 37.39% <60.71%> (+0.19%) ⬆️

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.

Copy link
Member

@joemcgill joemcgill left a comment

Choose a reason for hiding this comment

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

These changes look good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Speculative Loading Issues for the Speculative Loading plugin (formerly Speculation Rules) [Type] Enhancement A suggestion for improvement of an existing feature
Projects
Status: Code Review 👀
Development

Successfully merging this pull request may close these issues.

2 participants