Skip to content

Commit

Permalink
Global Styles: Always load block CSS from __experimentalStyle (#42005)
Browse files Browse the repository at this point in the history
  • Loading branch information
scruffian committed Jun 28, 2022
1 parent 6e65955 commit e6a4fe4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
5 changes: 5 additions & 0 deletions lib/compat/wordpress-6.1/get-global-styles-and-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ function wp_add_global_styles_for_blocks() {
foreach ( $block_nodes as $metadata ) {
$block_css = $tree->get_styles_for_block( $metadata );

if ( ! wp_should_load_separate_core_block_assets() ) {
wp_add_inline_style( 'global-styles', $block_css );
continue;
}

if ( isset( $metadata['name'] ) ) {
$block_name = str_replace( 'core/', '', $metadata['name'] );
// These block styles are added on block_render.
Expand Down
19 changes: 8 additions & 11 deletions lib/compat/wordpress-6.1/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,22 @@ function gutenberg_enqueue_global_styles() {
return;
}

/**
* If we are loading CSS for each block separately, then we can load the theme.json CSS conditionally.
* This removes the CSS from the global-styles stylesheet and adds it to the inline CSS for each block.
*/
if ( $separate_assets ) {
add_filter( 'gutenberg_get_style_nodes', 'filter_out_block_nodes' );
// add each block as an inline css.
wp_add_global_styles_for_blocks();
}

$stylesheet = gutenberg_get_global_stylesheet();

if ( empty( $stylesheet ) ) {
return;
}

wp_register_style( 'global-styles', false, array(), true, true );
wp_add_inline_style( 'global-styles', $stylesheet );
wp_enqueue_style( 'global-styles' );

/**
* If we are loading CSS for each block separately, then we can load the theme.json CSS conditionally.
* This removes the CSS from the global-styles stylesheet and adds it to the inline CSS for each block.
*/
add_filter( 'gutenberg_get_style_nodes', 'filter_out_block_nodes' );
// add each block as an inline css.
wp_add_global_styles_for_blocks();
}

remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' );
Expand Down

0 comments on commit e6a4fe4

Please sign in to comment.