From 2bd2a2fe84c2ae656fd095cacd1bcd45a8aa9bc6 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 17 Aug 2023 16:37:46 +0000 Subject: [PATCH] Editor: Ensure defer loading strategy is only applied to a block's viewScript. Amends [56398]. Props gziolo, westonruter. Fixes #59115. git-svn-id: https://develop.svn.wordpress.org/trunk@56403 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/blocks.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 97c5951a0e..5f48c0af59 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -164,6 +164,11 @@ function register_block_script_handle( $metadata, $field_name, $index = 0 ) { : get_theme_file_uri( str_replace( $stylesheet_path_norm, '', $script_path_norm ) ); } + $script_args = array(); + if ( 'viewScript' === $field_name ) { + $script_args['strategy'] = 'defer'; + } + $script_asset = require $script_asset_path; $script_dependencies = isset( $script_asset['dependencies'] ) ? $script_asset['dependencies'] : array(); $result = wp_register_script( @@ -171,7 +176,7 @@ function register_block_script_handle( $metadata, $field_name, $index = 0 ) { $script_uri, $script_dependencies, isset( $script_asset['version'] ) ? $script_asset['version'] : false, - array( 'strategy' => 'defer' ) + $script_args ); if ( ! $result ) { return false;