From 1843b3ff5ea75852f0f82c95f0ab2fddaeb2e378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Zi=C3=B3=C5=82kowski?= Date: Wed, 20 Dec 2023 12:43:50 +0100 Subject: [PATCH 1/2] Modules: Load the import map polyfill when needed --- .../modules/class-gutenberg-modules.php | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/experimental/modules/class-gutenberg-modules.php b/lib/experimental/modules/class-gutenberg-modules.php index 0a2da03545776e..ebdc22e58e8b62 100644 --- a/lib/experimental/modules/class-gutenberg-modules.php +++ b/lib/experimental/modules/class-gutenberg-modules.php @@ -152,15 +152,21 @@ public static function print_module_preloads() { * import maps (https://github.com/guybedford/es-module-shims/issues/406). */ public static function print_import_map_polyfill() { - $import_map = self::get_import_map(); - if ( ! empty( $import_map['imports'] ) ) { - wp_print_script_tag( - array( - 'src' => gutenberg_url( '/build/modules/importmap-polyfill.min.js' ), - 'defer' => true, - ) - ); - } + $test = 'HTMLScriptElement.supports?.("importmap")'; + $src = gutenberg_url( '/build/modules/importmap-polyfill.min.js' ); + + echo ( + // Test presence of feature... + '' + ); } /** @@ -273,4 +279,4 @@ function gutenberg_dequeue_module( $module_identifier ) { add_action( $modules_position, array( 'Gutenberg_Modules', 'print_module_preloads' ) ); // Prints the script that loads the import map polyfill in the footer. -add_action( 'wp_footer', array( 'Gutenberg_Modules', 'print_import_map_polyfill' ), 11 ); +add_action( 'wp_head', array( 'Gutenberg_Modules', 'print_import_map_polyfill' ), 11 ); From 8f5e260136bec973b3f1b60583cc16c17378cb3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=B3=C5=82kowski?= Date: Wed, 3 Jan 2024 17:20:05 +0100 Subject: [PATCH 2/2] Update lib/experimental/modules/class-gutenberg-modules.php Co-authored-by: Felix Arntz --- lib/experimental/modules/class-gutenberg-modules.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/experimental/modules/class-gutenberg-modules.php b/lib/experimental/modules/class-gutenberg-modules.php index ebdc22e58e8b62..5aa012f8e2f2c5 100644 --- a/lib/experimental/modules/class-gutenberg-modules.php +++ b/lib/experimental/modules/class-gutenberg-modules.php @@ -152,7 +152,7 @@ public static function print_module_preloads() { * import maps (https://github.com/guybedford/es-module-shims/issues/406). */ public static function print_import_map_polyfill() { - $test = 'HTMLScriptElement.supports?.("importmap")'; + $test = 'HTMLScriptElement.supports && HTMLScriptElement.supports("importmap")'; $src = gutenberg_url( '/build/modules/importmap-polyfill.min.js' ); echo (