Move wp_load_classic_theme_block_styles_on_demand() from the init action to wp_default_styles#11232
Move wp_load_classic_theme_block_styles_on_demand() from the init action to wp_default_styles#11232westonruter wants to merge 3 commits intoWordPress:trunkfrom
wp_load_classic_theme_block_styles_on_demand() from the init action to wp_default_styles#11232Conversation
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
There was a problem hiding this comment.
Pull request overview
Adjusts when classic themes opt into on-demand block styles (and related output-buffer enhancements) by moving the setup hook earlier in the styles bootstrapping flow, and updates the related PHPUnit test setup ordering.
Changes:
- Move
wp_load_classic_theme_block_styles_on_demand()from aninithook towp_default_styles(priority0). - Document the required call ordering for
wp_load_classic_theme_block_styles_on_demand(). - Run per-test
$set_upclosures earlier intest_wp_hoist_late_printed_styles().
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/phpunit/tests/template.php | Runs test case setup earlier to align with the updated initialization timing. |
| src/wp-includes/script-loader.php | Adds documentation about required ordering for classic-theme on-demand block styles initialization. |
| src/wp-includes/default-filters.php | Changes the default hook timing for enabling classic-theme on-demand block styles. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…from `init` to `wp_default_styles`. This ensures the filters to opt in to loading separate block styles on demand are added at the moment `WP_Styles` is constructed. This accounts for styles being registered at the `init` action before `register_core_block_style_handles()` runs at priority 9. Without this, the `wp-block-library` stylesheet may get registered with the full combined block styles as `style.css` instead of just `common.css`, due to `wp_should_load_block_assets_on_demand()` still returning false. The `wp_default_styles` action still runs during `init`. Developed in #11232 Follow-up to r61008. Props westonruter, adamsilverstein. See #64099. Fixes #64846. git-svn-id: https://develop.svn.wordpress.org/trunk@61981 602fd350-edb4-49c9-b593-d223f7449a82
…from `init` to `wp_default_styles`. This ensures the filters to opt in to loading separate block styles on demand are added at the moment `WP_Styles` is constructed. This accounts for styles being registered at the `init` action before `register_core_block_style_handles()` runs at priority 9. Without this, the `wp-block-library` stylesheet may get registered with the full combined block styles as `style.css` instead of just `common.css`, due to `wp_should_load_block_assets_on_demand()` still returning false. The `wp_default_styles` action still runs during `init`. Developed in WordPress/wordpress-develop#11232 Follow-up to r61008. Props westonruter, adamsilverstein. See #64099. Fixes #64846. Built from https://develop.svn.wordpress.org/trunk@61981 git-svn-id: http://core.svn.wordpress.org/trunk@61263 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Trac ticket: https://core.trac.wordpress.org/ticket/64846
The
wp_load_classic_theme_block_styles_on_demand()function was added to run atinitaction with priority 8 in r61008. This turns out to be too late since styles can be registered earlier. Registering a style earlier causeswp_default_styles()to be called, which registers thewp-block-librarystyle. When a classic theme is active, beforewp_load_classic_theme_block_styles_on_demand()is run, thewp_should_load_block_assets_on_demand()function will returnfalse. This results in the combined block library stylesheet being incorrectly registered:wordpress-develop/src/wp-includes/script-loader.php
Lines 1819 to 1823 in 2bb252a
The point of
wp_load_classic_theme_block_styles_on_demand()is to opt-in to loading separate block styles on demand, but at the point it runs it is already too late since the combinedwp-block-libraryhas already been registered.If the
initpriority ofwp_load_classic_theme_block_styles_on_demand()is changed to-1then this fixes the problem, but this is not the ideal solution since a theme/plugin could always register a style earlier during theinitaction (e.g.PHP_INT_MIN). Note that theinitaction is the earliest point to register a style safely since_wp_scripts_maybe_doing_it_wrong()will issue a warning otherwise. Nevertheless, the better solution would be to not use theinitaction at all, but rather to use thewp_default_stylesaction (with a low priority) so that we'll be better guaranteed that the filters will have been added.The issue can be reproduced with the following example plugin:
Before ❌
After ✅
Use of AI Tools
None 🧠
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.