-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Error in register_block_style when should_load_separate_core_block_assets is turned on. #35912
Comments
Hmmm
It could be... But using the code posted above I was unable to replicate an issue and therefore couldn't debug it. |
Thanks for the comment. Hmmm. The theme happens with Twenty Twenty-One. I've never heard of the It means that when I use postscript: If the |
For enqueueing stylesheets specific to a single block, you can use the code from this post: https://make.wordpress.org/core/2021/07/01/block-styles-loading-enhancements-in-wordpress-5-8/ Since I'm not getting an error with the code you posted, a semi-random idea: Did you try naming your stylesheet something that does not conflict with block-names? So instead of |
@aristath
Here is the complete code
Of course, this error message will only be displayed on pages that use the heading block. |
I tried the code posted above:
As soon as I activate the plugin, I'm getting the following error:
After fixing that, I can replicate the issue. I've already found the solution to it, so I'll create a new ticket in WP-Core and push a patch for it 👍 The code I used to replicate: <?php
/**
* Plugin Name: My Plugin
*/
add_filter( 'should_load_separate_core_block_assets', '__return_true' );
add_action( 'wp_enqueue_scripts', 'test_registering_a_block_style' );
add_action( 'admin_enqueue_scripts', 'test_registering_a_block_style' );
function test_registering_a_block_style() {
wp_register_style(
'my-theme-block-styles-core-heading',
plugins_url( 'style.css', __FILE__ ),
);
}
register_block_style(
'core/heading',
array(
'name' => 'my-theme-block-styles-core-heading-add',
'label' => 'Add',
'style_handle' => 'my-theme-block-styles-core-heading',
// 'inline_style' => '.wp-block-heading.is-style-heading-add , .is-style-heading-add { color: blue; }',
)
); Thank you for sticking with it and providing the necessary information to debug it! ❤️ |
Error reported in https://core.trac.wordpress.org/ticket/54323 and patch submitted. |
@aristath thanks for the prompt fix; can we close this ticket then? @shimon246 |
The WordPress `enqueue_block_styles_assets` function contains a bug which may lead to fatal errors for full site editing enabled themes which register custom styles and are missing a HTML template for request (for instance 404.html). The bug was patched in WordPress core ( see https://core.trac.wordpress.org/ticket/54323 ), but since the Gutenberg 11.8.0 introduces the following line: ``` add_filter( 'should_load_separate_core_block_assets', '__return_true' ); ``` it also should patch the issue, in order to prevent fatal errors for the themes matching the above mentioned criteria. See WordPress#35912 and WordPress#35903
Sorry for commenting on an already closed issue, but I believe that it might be actually helpful, if Gutenberg could patch the issue now originating in WordPress, since in v11.8.0, it enforces the One such an example is the blockbase theme, which in it's latest version removes the block template for 404 page, and hits the bug (if run on WordPress 5.8 with Gutenberg 11.8.0). I have kindly opened a PR with proposed fix for Gutenberg. |
@aristath I think this code only loads the css specified in style_handle when the core heading block is used.
#35912 (comment) Is this normal behavior? |
Yes, it's normal. We haven't (yet) applied to JS the same optimizations we've applied to CSS, that is a work in progress and will land at some point. 👍 |
@aristath |
Description
I get an error with register_block_style when I turn on should_load_separate_core_block_assets.
(=
add_filter( 'should_load_separate_core_block_assets', '__return_true' );
)Code
Error message
Fatal error: Uncaught ArgumentCountError: Too few arguments to function {closure}(), 1 passed in /var/www/html/wp-includes/class-wp-hook.php on line 305 and exactly 2 expected in /var/www/html/wp-includes/script-loader.php:2447 Stack trace: #0 /var/www/html/wp-includes/class-wp-hook.php(305): {closure}('\n
The relevant code
class-wp-hook.php 305
https://github.com/WordPress/wordpress-develop/blob/master/src/wp-includes/class-wp-hook.php#L305
script-loader.php 2451
https://github.com/WordPress/wordpress-develop/blob/master/src/wp-includes/script-loader.php#L2451-L2453
Expected behavior
If heading-default is set, the CSS (style.css) will be loaded, and if heading-default is not set, the CSS will not be loaded.
Related references
https://make.wordpress.org/core/2021/07/01/block-styles-loading-enhancements-in-wordpress-5-8/#comment-41478
https://core.trac.wordpress.org/ticket/53616
WordPress/wordpress-develop#1482
register_block_type is working fine.
Is register_block_style still being worked on?
If so, please let me know.
Step-by-step reproduction instructions
1.
add_filter( 'should_load_separate_core_block_assets', '__return_true' );
for custom plugins etc.2.Prepare the CSS
build/core/heading/style.css
3.Paste the code to add the style for the heading block
The text was updated successfully, but these errors were encountered: