Repository navigation
Script Loader: Load the style handle of a custom block style when the block is on the page - #14461
faisalahammad wants to merge 1 commit into
Conversation
When block assets load on demand, the stylesheet passed as `style_handle` to `register_block_style()` was enqueued from a `render_block` filter added in `enqueue_block_styles_assets()`. That function runs on `enqueue_block_assets`, which fires in `wp_head()`. Block themes render the whole template before `wp_head()`, so the filter was added after every block had rendered and the stylesheet was never loaded. This moves the on-demand enqueue into `WP_Block::render()`, next to the block's own style handles. Handles registered after the block renders, for example on `enqueue_block_assets`, are still enqueued once registered. When block assets do not load on demand, `enqueue_block_styles_assets()` keeps enqueuing them as before. Props alexandrebuffet, daymobrew, drivingralle, pagelab, petitphp, poena, jonsurrell, westonruter, wido. Fixes #55184.
|
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. |
|
Thanks for working on this, @faisalahammad! Moving the block style stylesheet enqueue into Patch Testing ReportPatch tested: #14461 Environment
Steps taken
Expected result
Additional Notes
|
https://core.trac.wordpress.org/ticket/55184
What and why
When block assets load on demand, a stylesheet passed as
style_handletoregister_block_style()is never loaded, even when the block is on the page.enqueue_block_styles_assets()adds arender_blockfilter to enqueue it, but it runs onenqueue_block_assetsinsidewp_head(), and block themes render the whole template beforewp_head(). This PR moves the on-demand enqueue intoWP_Block::render(), next to the block's own style handles, so it happens as each block renders.Scope
style_handlestylesheets when block assets load on demand. Handles registered after the block renders, for example onenqueue_block_assets, are still enqueued once registered.enqueue_block_styles_assets()enqueues them as before.inline_stylehandling is not touched.style_handle#6628, which enqueued onwp_loadedand missed handles registered later.Testing
Unit tests:
Manual:
npm run env:start, then activate Twenty Twenty-Five.<link id='my-fancy-heading-css'>. With this PR it is printed in<head>.