From 1e94019ed6e8d5a785625451a9179e81dc5f8303 Mon Sep 17 00:00:00 2001 From: Carlos Bravo Date: Fri, 26 Jan 2024 11:09:25 +0100 Subject: [PATCH] Do not load polyfill if there are no modules --- .../wordpress-6.5/class-wp-script-modules.php | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/compat/wordpress-6.5/class-wp-script-modules.php b/lib/compat/wordpress-6.5/class-wp-script-modules.php index c51be714384621..c004da668e441d 100644 --- a/lib/compat/wordpress-6.5/class-wp-script-modules.php +++ b/lib/compat/wordpress-6.5/class-wp-script-modules.php @@ -235,21 +235,24 @@ public function print_import_map() { * @since 6.5.0 */ public function print_import_map_polyfill() { - $test = 'HTMLScriptElement.supports && HTMLScriptElement.supports("importmap")'; - $src = defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ? gutenberg_url( '/build/modules/importmap-polyfill.min.js' ) : includes_url( 'js/dist/vendor/wp-polyfill-importmap.min.js' ); + $import_map = $this->get_import_map(); + if ( ! empty( $import_map['imports'] ) ) { + $test = 'HTMLScriptElement.supports && HTMLScriptElement.supports("importmap")'; + $src = defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ? gutenberg_url( '/build/modules/importmap-polyfill.min.js' ) : includes_url( 'js/dist/vendor/wp-polyfill-importmap.min.js' ); - echo ( - // Test presence of feature... - '' - ); + echo ( + // Test presence of feature... + '' + ); + } } /** * Returns the import map array.