Skip to content

Commit 345fb48

Browse files
committed
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
1 parent 0f0d34e commit 345fb48

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/wp-includes/blocks.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ function register_block_script_handle( $metadata, $field_name, $index = 0 ) {
181181
$script_uri = get_block_asset_url( $script_path_norm );
182182

183183
$script_args = array();
184-
if ( 'viewScript' === $field_name ) {
184+
if ( 'viewScript' === $field_name && $script_uri ) {
185185
$script_args['strategy'] = 'defer';
186186
}
187187

0 commit comments

Comments
 (0)