diff --git a/packages/block-library/src/file/block.json b/packages/block-library/src/file/block.json index 0cc20b3f501e9..1b74b46dacdbc 100644 --- a/packages/block-library/src/file/block.json +++ b/packages/block-library/src/file/block.json @@ -72,7 +72,6 @@ }, "interactivity": true }, - "viewScript": "file:./view.min.js", "editorStyle": "wp-block-file-editor", "style": "wp-block-file" } diff --git a/packages/block-library/src/file/index.php b/packages/block-library/src/file/index.php index 042ea89970736..328b4d0f5e2e7 100644 --- a/packages/block-library/src/file/index.php +++ b/packages/block-library/src/file/index.php @@ -16,19 +16,8 @@ */ function render_block_core_file( $attributes, $content, $block ) { $should_load_view_script = ! empty( $attributes['displayPreview'] ); - $view_js_file = 'wp-block-file-view'; - // If the script already exists, there is no point in removing it from viewScript. - if ( ! wp_script_is( $view_js_file ) ) { - $script_handles = $block->block_type->view_script_handles; - - // If the script is not needed, and it is still in the `view_script_handles`, remove it. - if ( ! $should_load_view_script && in_array( $view_js_file, $script_handles, true ) ) { - $block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file ) ); - } - // If the script is needed, but it was previously removed, add it again. - if ( $should_load_view_script && ! in_array( $view_js_file, $script_handles, true ) ) { - $block->block_type->view_script_handles = array_merge( $script_handles, array( $view_js_file ) ); - } + if ( $should_load_view_script ) { + gutenberg_enqueue_module( '@wordpress/block-library/file-block' ); } // Update object's aria-label attribute if present in block HTML. @@ -96,5 +85,14 @@ function register_block_core_file() { 'render_callback' => 'render_block_core_file', ) ); + + gutenberg_register_module( + '@wordpress/block-library/file-block', + '/wp-content/plugins/gutenberg/build/interactivity/file.min.js', + 'frontend', + array( + 'version' => defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' ), + ) + ); } add_action( 'init', 'register_block_core_file' ); diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index d232f6953171f..99d43e1648e60 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -638,7 +638,7 @@ function render_block_core_navigation( $attributes, $content, $block ) { $should_load_view_script = ( $has_submenus && ( $attributes['openSubmenusOnClick'] || $attributes['showSubmenuIcon'] ) ) || $is_responsive_menu; - // Load the modules. + // Load the module. if ( $should_load_view_script ) { gutenberg_enqueue_module( '@wordpress/block-library/navigation-block' ); } diff --git a/packages/block-library/src/search/block.json b/packages/block-library/src/search/block.json index 5669a9089d0e0..93018c2c29f4c 100644 --- a/packages/block-library/src/search/block.json +++ b/packages/block-library/src/search/block.json @@ -91,7 +91,6 @@ }, "html": false }, - "viewScript": "file:./view.min.js", "editorStyle": "wp-block-search-editor", "style": "wp-block-search" } diff --git a/packages/block-library/src/search/index.php b/packages/block-library/src/search/index.php index f00ecfe6abe1c..bfc52f032d04f 100644 --- a/packages/block-library/src/search/index.php +++ b/packages/block-library/src/search/index.php @@ -85,21 +85,9 @@ function render_block_core_search( $attributes, $content, $block ) { // Adding these attributes manually is needed until the Interactivity API SSR logic is added to core. $input->set_attribute( 'aria-hidden', 'true' ); $input->set_attribute( 'tabindex', '-1' ); - } - - // If the script already exists, there is no point in removing it from viewScript. - $view_js_file = 'wp-block-search-view'; - if ( ! wp_script_is( $view_js_file ) ) { - $script_handles = $block->block_type->view_script_handles; - // If the script is not needed, and it is still in the `view_script_handles`, remove it. - if ( ! $is_expandable_searchfield && in_array( $view_js_file, $script_handles, true ) ) { - $block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file ) ); - } - // If the script is needed, but it was previously removed, add it again. - if ( $is_expandable_searchfield && ! in_array( $view_js_file, $script_handles, true ) ) { - $block->block_type->view_script_handles = array_merge( $script_handles, array( $view_js_file ) ); - } + // Load the module. + gutenberg_enqueue_module( '@wordpress/block-library/search-block' ); } } @@ -203,27 +191,17 @@ function register_block_core_search() { 'render_callback' => 'render_block_core_search', ) ); -} -add_action( 'init', 'register_block_core_search' ); -/** - * Ensure that the view script has the `wp-interactivity` dependency. - * - * @since 6.4.0 - * - * @global WP_Scripts $wp_scripts - */ -function block_core_search_ensure_interactivity_dependency() { - global $wp_scripts; - if ( - isset( $wp_scripts->registered['wp-block-search-view'] ) && - ! in_array( 'wp-interactivity', $wp_scripts->registered['wp-block-search-view']->deps, true ) - ) { - $wp_scripts->registered['wp-block-search-view']->deps[] = 'wp-interactivity'; - } + gutenberg_register_module( + '@wordpress/block-library/search-block', + '/wp-content/plugins/gutenberg/build/interactivity/search.min.js', + 'frontend', + array( + 'version' => defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' ), + ) + ); } - -add_action( 'wp_print_scripts', 'block_core_search_ensure_interactivity_dependency' ); +add_action( 'init', 'register_block_core_search' ); /** * Builds the correct top level classnames for the 'core/search' block. diff --git a/tools/webpack/interactivity.js b/tools/webpack/interactivity.js index 8abc3343c724b..6f43caafee227 100644 --- a/tools/webpack/interactivity.js +++ b/tools/webpack/interactivity.js @@ -16,6 +16,8 @@ module.exports = { navigation: './packages/block-library/src/navigation/view.js', query: './packages/block-library/src/query/view.js', image: './packages/block-library/src/image/view.js', + file: './packages/block-library/src/file/view.js', + search: './packages/block-library/src/search/view.js', }, experiments: { outputModule: true,