Preloading the REST API causes issues with manual plugin updates #47266
Labels
focus: install-uninstall
Issues related to installing, uninstalling, and upgrades.
focus: rest api
Issues related to WooCommerce REST API.
team: Proton
Prerequisites
Describe the bug
At Transact, we have faced multiple issues while testing new WooPayments plugin versions, and it seems the reason is that the REST API is being initialized at inappropriate times.
Related to this topic, we some of the discussions we had include paJDYF-aZa-p2, p1715098461138369-slack-CGGCLBN58, and Automattic/woocommerce-payments#7464. However, we have faced similar issues upon multiple releases.
I can see that others have experienced similar behavior in different contexts, including upon Woo updates:
Initializing the REST API can cause hidden delays on most, if not all, admin pages. On a random Jurassic Ninja site with Woo and WooPayments active, REST API preloading adds about ~120ms to a ~1000ms page load, which is not massive, but not negligible either.
The bigger issue we're facing is upon manual plugin updates. Here's what happens:
The described behavior happens anytime REST controller constructor parameters are added, or rearranged. The error that appears looks like this:
Once the error is displayed, there are no further side effects, as on subsequent page loads, the right environment is in place. However, this causes concerns with both developers and merchants.
Expected behavior
REST API endpoints should only be preloaded in applicable contexts, whenever it is actually needed.
Actual behavior
rest_preload_api_request()
is called upon any admin page visit.Steps to reproduce
I will not add details on how to make the error appear, just how to simulate the environment:
woocommerce/plugins/woocommerce/src/Internal/Admin/Loader.php
Lines 322 to 329 in 3ad9ebf
woocommerce/plugins/woocommerce/src/Internal/Admin/Settings.php
Lines 140 to 147 in 3ad9ebf
The whole process relies on
AssetDataRegistry
checking whether a specific script, ex.wc-settings
is being enqueued. This seems to be a bit inconsistent by itself, so replacing this line withif ( true ) {
helps with debugging:woocommerce/plugins/woocommerce/src/Blocks/Assets/AssetDataRegistry.php
Line 383 in 3ad9ebf
WordPress Environment
Nothing specific, this issue has persisted throughout multiple versions.
Isolating the problem
The text was updated successfully, but these errors were encountered: