From 834693d4a2223a52bb3f78ab410c8a867108aa5d Mon Sep 17 00:00:00 2001 From: Luis Herranz Date: Tue, 9 Jan 2024 17:57:58 +0100 Subject: [PATCH] Add suffixes to the ids and an id to the import map --- src/wp-includes/class-wp-modules.php | 5 +++-- tests/phpunit/tests/modules/wpModules.php | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/class-wp-modules.php b/src/wp-includes/class-wp-modules.php index cc80f073e0b0b..63b8e25a691cf 100644 --- a/src/wp-includes/class-wp-modules.php +++ b/src/wp-includes/class-wp-modules.php @@ -172,7 +172,7 @@ public function print_enqueued_modules() { array( 'type' => 'module', 'src' => $this->get_versioned_src( $module ), - 'id' => $module_id, + 'id' => $module_id . '-js-module', ) ); } @@ -199,7 +199,7 @@ public function print_module_preloads() { echo sprintf( '', esc_url( $this->get_versioned_src( $module ) ), - esc_attr( $module_id ) + esc_attr( $module_id . '-js-modulepreload' ) ); } } @@ -217,6 +217,7 @@ public function print_import_map() { wp_json_encode( $import_map, JSON_HEX_TAG | JSON_HEX_AMP ), array( 'type' => 'importmap', + 'id' => 'wp-importmap', ) ); } diff --git a/tests/phpunit/tests/modules/wpModules.php b/tests/phpunit/tests/modules/wpModules.php index 3ff6bc46da42d..58c8a9c027307 100644 --- a/tests/phpunit/tests/modules/wpModules.php +++ b/tests/phpunit/tests/modules/wpModules.php @@ -43,7 +43,8 @@ public function get_enqueued_modules() { 'import' => 'module', ) ) ) { - $enqueued_modules[ $p->get_attribute( 'id' ) ] = $p->get_attribute( 'src' ); + $id = preg_replace( '/-js-module$/', '', $p->get_attribute( 'id' ) ); + $enqueued_modules[ $id ] = $p->get_attribute( 'src' ); } return $enqueued_modules; @@ -56,7 +57,7 @@ public function get_enqueued_modules() { */ public function get_import_map() { $import_map_markup = get_echo( array( $this->modules, 'print_import_map' ) ); - preg_match( '/