From 345fb48865215a1675ef209820951f6a4cf1e50d Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Fri, 29 Sep 2023 13:13:54 +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 git-svn-id: https://develop.svn.wordpress.org/trunk@56744 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/blocks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 482955ea21..d48ee3fa57 100644 --- a/src/wp-includes/blocks.php +++ b/src/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'; }