Opened 4 weeks ago
Last modified 4 days ago
#65272 accepted defect (bug)
Blocks' opinionated styles are not loading on demand in classic themes
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 7.0.1 | Priority: | normal |
| Severity: | normal | Version: | 7.0 |
| Component: | Script Loader | Keywords: | has-patch has-unit-tests |
| Focuses: | Cc: |
Description
Steps to Reproduce the issue :-
- Install WordPress 7.0 RC4
- Activate Twenty Fifteen theme.
- Take Quote block.
- Choose Text alignment right and align left.
You can able to see editor side it works fine but front side text is aligned right but border remains same left aligned which is not okay if text is aligned right.
Attachments (2)
Change History (15)
#1
@
4 weeks ago
- Summary changed from Twenty Fifteen - Quote block issue with border with latest wordpress update. to Twenty Fifteen: Quote block border is on the left when text is aligned right
- Version trunk deleted
#2
@
4 weeks ago
- Version set to trunk
Removing trunk version as this is not going to be shipped with WP 7.0 but in the next releases.
#4
follow-up:
↓ 6
@
4 weeks ago
- Component changed from Bundled Theme to Script Loader
- Milestone changed from 7.1 to 7.0.1
- Summary changed from Twenty Fifteen: Quote block border is on the left when text is aligned right to Blocks' opinionated styles are not loading on demand in classic themes
- Version set to trunk
This bug is new to 7.0, but not with the theme(s).
The Quote block border issue can happen in Twenty Fifteen and Twenty Nineteen. However, the theme.css for individual blocks such as Quote, Search, etc., are not loading.
I can temporarily correct the behavior by
- adding
wp_load_classic_theme_block_styles_on_demandon theinitaction, as it was before [61981], or - disabling the
should_load_separate_core_block_assetsfilter and loading the fullwp-block-library-themestylesheet.
This ticket was mentioned in PR #11887 on WordPress/wordpress-develop by @khokansardar.
4 weeks ago
#5
- Keywords has-patch has-unit-tests added
## What
Restores the init priority 8 hook for wp_load_classic_theme_block_styles_on_demand() while keeping the wp_default_styles priority 0 hook added in [61981]. Adds guards so filters and actions are not registered twice when the function runs from both hooks.
## Why
In WordPress 7.0, commit 61981 moved wp_load_classic_theme_block_styles_on_demand() from init priority 8 to wp_default_styles priority 0 only. That introduced a regression (#65272):
register_core_block_style_handles()runs atinitpriority 9.- It checks
wp_should_load_separate_core_block_assets()before callingwp_styles(). - With only the
wp_default_styleshook, those filters are not added untilWP_Stylesis first constructed. register_core_block_style_handles()returns early, so per-block opinionated styles (blocks/*/theme.css, e.g.wp-block-quote-theme) are never registered or enqueued on the frontend.
Symptom: In classic themes with wp-block-styles support (e.g. Twenty Fifteen), Quote block right alignment works in the editor but the border stays on the left on the frontend because theme.css never loads.
The wp_default_styles hook remains so filters are still present when WP_Styles is constructed before init priority 9 (#64846).
## How
- Re-add
add_action( 'init', 'wp_load_classic_theme_block_styles_on_demand', 8 )indefault-filters.php. - Keep
add_action( 'wp_default_styles', 'wp_load_classic_theme_block_styles_on_demand', 0 ). - Use
has_filter()/has_action()before adding hooks to avoid duplicate registration. - Add regression test:
Tests_Blocks_ClassicThemeBlockStylesOnDemand::test_register_core_block_style_handles_without_prior_wp_styles.
#6
in reply to:
↑ 4
@
4 weeks ago
Replying to sabernhardt:
I can temporarily correct the behavior by
- adding
wp_load_classic_theme_block_styles_on_demandon theinitaction, as it was before [61981], or
Right, the change in r61981 was done intentionally, so reverting it will break something else. See #64846.
We'll need to figure something else for this.
@westonruter commented on PR #11887:
4 weeks ago
#7
Does this cause a regression in what r61981 was committed to fix Core-64846?
#8
@
4 weeks ago
I was able to get the individual theme.css stylesheets again by changing the priority for register_core_block_style_handles from 9 to the default 10, but I do not know what else that changes.
add_action( 'init', 'register_core_block_style_handles', 10 );
@khokansardar commented on PR #11887:
4 weeks ago
#9
Does this cause a regression in what r61981 was committed to fix Core-64846?
Thanks @westonruter — good catch on has_filter() / has_action() returning priority 0, which is falsy. Updated all four checks to use false ===.
Re #64846: this should not regress r61981 because the wp_default_styles priority 0 hook is retained. That hook ensures filters are present when WP_Styles is constructed before init priority 9, so wp-block-library still registers as common.css.
#13
@
4 days ago
I would like to ask if you can give an ETA for a fix (https://github.com/WordPress/wordpress-develop/pull/11887 – ?) and update?
I have attached video for better understanding.