Skip to content

Commit e533437

Browse files
committed
Block Supports: Ensure custom CSS prints after block library styles.
The `wp-block-custom-css` handle depended only on `global-styles`, which pulled `global-styles` forward in the print order, ahead of `wp-block-library`. Block library default styles then printed last and overrode global styles. Declare `wp-block-library` before `global-styles` in the handle's dependency array so `wp-block-library` prints first and `global-styles` keeps winning the cascade. Developed in: WordPress#12461 Follow-up to [61678], [62656]. Props ramonopoly, westonruter, wildworks. Fixes #65602. git-svn-id: https://develop.svn.wordpress.org/trunk@62706 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 0d59cc4 commit e533437

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/wp-includes/block-supports/custom-css.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ function wp_render_custom_css_support_styles( $parsed_block ) {
6969

7070
if ( ! empty( $processed_css ) ) {
7171
/**
72-
* Skip CSS that has already been added. Blocks with identical attributes
73-
* share the same class name and processed CSS via {@see wp_unique_id_from_values()},
74-
* so the same style would otherwise be enqueued more than once (e.g. inside
75-
* a Query Loop or when blocks share identical custom CSS).
72+
* Reuse one handle so identical custom CSS is enqueued only once via
73+
* {@see wp_unique_id_from_values()}. Explicitly declare the `wp-block-library`
74+
* dependency so `global-styles` is guaranteed to print after it, preventing
75+
* block default styles from unintentionally overriding global styles.
7676
*/
7777
$handle = 'wp-block-custom-css';
7878
if ( ! wp_style_is( $handle, 'registered' ) ) {
79-
wp_register_style( $handle, false, array( 'global-styles' ) );
79+
wp_register_style( $handle, false, array( 'wp-block-library', 'global-styles' ) );
8080
}
8181
$after_styles = wp_styles()->get_data( $handle, 'after' );
8282
if ( ! is_array( $after_styles ) ) {

0 commit comments

Comments
 (0)