From dc853cb0e9d14d649ea75cb8a278f57a9a60950e Mon Sep 17 00:00:00 2001 From: audrasjb Date: Sun, 28 Nov 2021 21:12:06 +0000 Subject: [PATCH] Script Loader: Enqueue block stylesheet only when the corresponding block is used. Before this change, block stylesheets were enqueued although the corresponding blocks were not used in the current post, even if the `should_load_separate_core_block_assets` filter was set to `true`. Props shimotomoki, devutpol, audrasjb. Fixes #54457. Built from https://develop.svn.wordpress.org/trunk@52262 git-svn-id: http://core.svn.wordpress.org/trunk@51854 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/script-loader.php | 10 +++++++--- wp-includes/version.php | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 972b4497a6..7ffa2d5fde 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -2459,10 +2459,14 @@ function enqueue_block_styles_assets() { if ( wp_should_load_separate_core_block_assets() ) { add_filter( 'render_block', - function( $html ) use ( $style_properties ) { - wp_enqueue_style( $style_properties['style_handle'] ); + function( $html, $block ) use ( $block_name, $style_properties ) { + if ( $block['blockName'] === $block_name ) { + wp_enqueue_style( $style_properties['style_handle'] ); + } return $html; - } + }, + 10, + 2 ); } else { wp_enqueue_style( $style_properties['style_handle'] ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 1cf6a10481..316458dfd7 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-52261'; +$wp_version = '5.9-alpha-52262'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.