Repository navigation
wp-build: Keep the site data preload working with WordPress 7.1 core-data - #54396
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. Boost plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryThis PR did not change code coverage! That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷 |
| // same fields in the same order, or the preload is never consumed. | ||
| $preload_paths = array( | ||
| '/?_fields=description,generate_animated_image_subsizes,gmt_offset,home,image_max_bit_depth,image_sizes,image_size_threshold,image_strip_meta,name,site_icon,site_icon_url,site_logo,timezone_string,url,page_for_posts,page_on_front,show_on_front', | ||
| + // WordPress 7.1's bundled core-data requests this list, without generate_animated_image_subsizes. |
There was a problem hiding this comment.
WordPress 7.0 and older Gutenberg plugin versions such as 23.5.0 ask for different lists, so they still make the live request and can still show "Something went wrong!", same as before the 0.26 update. I'm leaving that for now because another key would cost every site one more dispatch.
| $preload_paths = array( | ||
| '/?_fields=description,generate_animated_image_subsizes,gmt_offset,home,image_max_bit_depth,image_sizes,image_size_threshold,image_strip_meta,name,site_icon,site_icon_url,site_logo,timezone_string,url,page_for_posts,page_on_front,show_on_front', | ||
| + // WordPress 7.1's bundled core-data requests this list, without generate_animated_image_subsizes. | ||
| + '/?_fields=description,gmt_offset,home,image_max_bit_depth,image_sizes,image_size_threshold,image_strip_meta,name,site_icon,site_icon_url,site_logo,timezone_string,url,page_for_posts,page_on_front,show_on_front', |
There was a problem hiding this comment.
This adds one more REST index dispatch to every wp-build page, about 5 ms and 1 KB of inline data, and only 7.1 sites on the bundled core-data read it. I'm fine with 7.0, 7.2 and 7.1 with a newer Gutenberg plugin paying that for nothing, because on 7.1 it replaces a browser request that can take the whole page down.
| @@ -182 +203 @@ | ||
| - JS; | ||
| +JS; | ||
| diff --git a/templates/page.php.template b/templates/page.php.template |
There was a problem hiding this comment.
This patch is hand-edited, so the first file's index line is stale and this file has no index line. It still applies and installs, so I've left both as they are.
| // same fields in the same order, or the preload is never consumed. | ||
| $preload_paths = array( | ||
| '/?_fields=description,generate_animated_image_subsizes,gmt_offset,home,image_max_bit_depth,image_sizes,image_size_threshold,image_strip_meta,name,site_icon,site_icon_url,site_logo,timezone_string,url,page_for_posts,page_on_front,show_on_front', | ||
| + // WordPress 7.1's bundled core-data requests this list, without generate_animated_image_subsizes. |
There was a problem hiding this comment.
This is the same comment as in page-wp-admin.php.template, and the comment above the array is repeated the same way. The two templates are separate files with no shared place to put it.
| $preload_paths = array( | ||
| '/?_fields=description,generate_animated_image_subsizes,gmt_offset,home,image_max_bit_depth,image_sizes,image_size_threshold,image_strip_meta,name,site_icon,site_icon_url,site_logo,timezone_string,url,page_for_posts,page_on_front,show_on_front', | ||
| + // WordPress 7.1's bundled core-data requests this list, without generate_animated_image_subsizes. | ||
| + '/?_fields=description,gmt_offset,home,image_max_bit_depth,image_sizes,image_size_threshold,image_strip_meta,name,site_icon,site_icon_url,site_logo,timezone_string,url,page_for_posts,page_on_front,show_on_front', |
There was a problem hiding this comment.
Both lists are hard-coded and nothing checks them against core-data, so the next core-data field change goes unnoticed until the live request fails and the page shows the error. This fixes today's mismatch, and I'm leaving a guard for separate work.
xavier-lc
left a comment
There was a problem hiding this comment.
The new key is correct. It matches the _fields list in WordPress 7.1.4's bundled core-data.js exactly, same fields in the same order. The original key still covers sites running the Gutenberg plugin. Hunk offsets and the lockfile hash swap check out.
Suggestion: add changelog entries. The error is visible on My Jetpack, Newsletter, Jetpack Settings and Boost. Without entries, the fix won't appear in the Jetpack 16.4 or Boost 4.9.0 changelog or readme.txt. #51078, the last change to this patch, added entries to the projects it affected. At minimum: packages/my-jetpack, packages/newsletter, plugins/jetpack and plugins/boost, e.g. My Jetpack: Fix "Something went wrong!" on WordPress 7.1 when the site data request fails.
|
Good call @xavier-lc, I've added changelog entries for My Jetpack, Newsletter, Jetpack and Boost. |
xavier-lc
left a comment
There was a problem hiding this comment.
Thanks, the changelog entries look good. Approving.
| # The patch also preloads WordPress 7.1's site-data field list. Keep that preload | ||
| # until Jetpack's minimum WordPress version requests the @wordpress/build 0.26 list, | ||
| # even if upstream fixes init-module handling first. |
There was a problem hiding this comment.
It seems such an issue should be fixed upstream as well; if there's a patch here, why not push it upstream?
There was a problem hiding this comment.
@tbradsha I've opened WordPress/gutenberg#86185 upstream so a failed prefetch can't take the whole page down.
The preload here is still needed until our minimum WordPress version asks for the new field list.
There was a problem hiding this comment.
I'm wary of patches to dependencies in general, but this one in particular seems quite prone to going stale. Wouldn't it be better if at least the upstream fix proposed matched the one we have here (along with a link to the upstream PR that hopefully would be merged and fix the issue)?
There was a problem hiding this comment.
Hmmm, I'd like this, but the upstream fix lives in @wordpress/boot, and Jetpack's pages can load WordPress's own boot instead of ours, so patching it here might not reach the 7.1 sites that crash. The preload is the part we know reaches them unfortunately. Though if we think this edge case is unlikely I'm happy with doing it the upstream patch way for consistency
I'll link WordPress/gutenberg#86185 from the patch note, and we can drop the preload once our minimum WordPress has the new field list. OK to merge this as is before the cut?
There was a problem hiding this comment.
Yep, let's go ahead and merge.
tbradsha
left a comment
There was a problem hiding this comment.
I'm not a fan of the wp-build hacks, but I don't think we have much choice at this point.
Fixes JETPACK-3476
Proposed changes
Preload both site-data field lists in both generated page templates. This ships with Jetpack 16.4, Boost 4.9.0 and subsequent plugin builds, without a switch.
Why are these changes being made?
@wordpress/build0.26 preloads a different field list from WordPress 7.1's core-data. My Jetpack, Newsletter, Settings and Boost therefore make a browser request, and if it fails the page is replaced with “Something went wrong!”. Both keys preserve the newer match.WordPress 7.0 asks for a different list and still makes the request, as it did before the 0.26 update.
One more in-process REST index dispatch per render costs about 5 ms and 1 KB of inline data (33 bytes gzipped), measured locally, more on sites with many REST routes. It replaces a full browser request on WordPress 7.1.
Related product discussion/links
None.
Does this pull request change what data or activity we track or use?
No.
Testing instructions
Checked on Docker with WordPress 7.1 and system Chrome at 1440/390 px. Offline mode and Newsletter used local fixtures. Hosted sites and real connections were not checked.
Use a WordPress 7.1 site without the Gutenberg plugin active.
/wp-json/?_fields=requests in browser DevTools.Screenshots
Captured on Docker with the site-data request forced to return HTTP 429.
Pipeline
Updates from git push no-mistakes