Opened 3 months ago
Closed 3 months ago
#65547 closed defect (bug) (duplicate)
Classic theme on demand block styles loading regression
| Reported by: | rgcodes | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Script Loader | Version: | 7.0 |
| Severity: | major | Keywords: | |
| Cc: | Focuses: | css |
Description
Issue: WordPress 7.0 breaks native block styles loading for classic themes.
Steps to reproduce: A bare classic theme (style.css, functions.php with wp-block-styles theme support, index.php). Zero plugins installed. Add a group block with a background to a page in the editor.
Alternating between WordPress 6.9.4 and 7.0 reliably removes/adds the bug confirming the bug exists in 7.0
Symptom: Group block has default padding in the editor but no padding on the front-end. Native block styles are missing on the front-end
Diagnosis:
The hook registration for wp_load_classic_theme_block_styles_on_demand() — which adds the should_load_separate_core_block_assets filter — changed in wp-includes/default-filters.php:
<?php // 6.9 add_action( 'init', 'wp_load_classic_theme_block_styles_on_demand', 8 ); // 7.0 (default-filters.php:609) add_action( 'wp_default_styles', 'wp_load_classic_theme_block_styles_on_demand', 0 );
register_core_block_style_handles() (wp-includes/blocks/index.php:29, hooked at init:9 on line 144) has an early return on line 32:
<?php if ( ! wp_should_load_separate_core_block_assets() ) { return; }
wp_default_styles does not fire before init:9 in Core.
At init:9 (where register_core_block_style_handles() runs) → wp_should_load_separate_core_block_assets() returns false (its filter has no callbacks yet) → per-block wp-block-{name}-theme handles never registered with URLs.
At wp_enqueue_scripts (where wp_common_block_scripts_and_styles() runs at script-loader.php:2502) → wp_should_load_separate_core_block_assets() returns true (something has since instantiated wp_styles(), firing the filter attachment) → the ! wp_should_load_separate_core_block_assets() guard skips enqueuing wp-block-library-theme (the combined stylesheet) too.
Resulting in no block styles being loaded at all
Workaround:
Adding the following to a theme or plugin fixes the assets but shouldn't be needed:
<?php add_filter( 'should_load_separate_core_block_assets', '__return_true' ); add_filter( 'should_load_block_assets_on_demand', '__return_true' );
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Hi and thanks for the report!
This is already tracked on #65272, if you could continue the conversation there.