-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix enqueueing additional styles for blocks only when rendered #37848
Conversation
@aristath, is there a track ticket for this issue? We have to manually backport these changes since they're not part of the packages. |
There's no trac ticket for that, it was simply reported on https://make.wordpress.org/core/2021/12/15/using-multiple-stylesheets-per-block/#comment-42320 |
21fe2f5
to
4485c89
Compare
@Mamaduka do you want me to create a ticket on track for this issue? Or have you already done that? |
@aristath, core ticket, and the patch would be great to ship fix with RC2. |
Trac ticket & patch: https://core.trac.wordpress.org/ticket/54790 |
4485c89
to
ec6ded8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix works as expected. Thank you, Ari.
P.S. I had to test using WP 5.8.x since plugin functions aren't loading in 5.9 RC, and used img { border: 5px solid red; }
to make file existance immediately visible.
I see that these changes were already made to Core (https://core.trac.wordpress.org/changeset/52559) so just noting here to my future self that I only need to merge this into |
* Fix enqueueing additional styles for blocks only when rendered * phpcs fix * backport changes from core
Description
Issue reported in https://make.wordpress.org/core/2021/12/15/using-multiple-stylesheets-per-block/#comment-42320
In a block theme, additional block styles registered using the
wp_enqueue_block_style
function should only get printed when the block exists on a page. However, they currently always get rendered.This PR fixes the issue so that these styles will only get printed when a block gets rendered.
How has this been tested?
Using 5.0-RC, with the twentytwentytwo theme:
Added this in the theme's
functions.php
file:Then, I added a new
assets/blocks/gallery.css
file in the theme with these contents:Tested and confirmed that the styles only get added when the block exists.
Then switched to the twentytwentyone theme (or any other non-block theme), and confirmed that the styles get added regardless of whether the block exists on a page or not (conditional stylesheets loading should only work for block themes)
This should be backported to 5.9 👍
Checklist:
*.native.js
files for terms that need renaming or removal).