From d922a9e96ae30ab019e136986c6858338e655981 Mon Sep 17 00:00:00 2001 From: spacedmonkey Date: Fri, 29 Sep 2023 13:15:25 +0000 Subject: [PATCH] Editor: Avoid Deferring Loading for Empty Block Script URI In the context of register_block_script_handle, the get_block_asset_url function may return false when an empty string is provided as the input. This behavior is intended to prevent the generation of invalid URLs. However, when the script loading strategy is set to "defer" while passing false, it triggers a "doing it wrong" message. This situation becomes problematic, especially for scenarios where the scripts haven't been built yet. In such cases, the realpath call returns an empty string because the file doesn't exist. To address this issue, we now perform a simple check to ensure that the script URI is not empty before applying the "defer" loading strategy. This adjustment prevents unnecessary deferral of loading for scripts with empty URIs. Follow on from [56683] and [56033]. Props kebbet, mukesh27, swissspidy, westonruter, spacedmonkey. Fixes #59475 Built from https://develop.svn.wordpress.org/trunk@56744 git-svn-id: http://core.svn.wordpress.org/trunk@56256 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/blocks.php | 2 +- wp-includes/version.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/wp-includes/blocks.php b/wp-includes/blocks.php index 482955ea21..d48ee3fa57 100644 --- a/wp-includes/blocks.php +++ b/wp-includes/blocks.php @@ -181,7 +181,7 @@ function register_block_script_handle( $metadata, $field_name, $index = 0 ) { $script_uri = get_block_asset_url( $script_path_norm ); $script_args = array(); - if ( 'viewScript' === $field_name ) { + if ( 'viewScript' === $field_name && $script_uri ) { $script_args['strategy'] = 'defer'; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 740ddf044d..1a9cff07a7 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.4-beta1-56743'; +$wp_version = '6.4-beta1-56744'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.