From 35f82135f1e7b1bd5486960a369f8896e48ebb33 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 29 Aug 2024 06:04:02 +0000 Subject: [PATCH] Script Loader: Remove `importmap` polyfill. The polyfill was added in [57492], but all browsers supported by WordPress already support import maps. This not only disables the polyfill, but completely removes it as it was only added recently and there is no usage outside of core. Props swissspidy, desrosj, luisherranz, gziolo. Fixes #60970. git-svn-id: https://develop.svn.wordpress.org/trunk@58952 602fd350-edb4-49c9-b593-d223f7449a82 --- package-lock.json | 11 ------- package.json | 1 - src/wp-includes/class-wp-script-modules.php | 14 -------- src/wp-includes/script-loader.php | 2 -- tests/phpunit/tests/dependencies/scripts.php | 8 ++--- .../tests/script-modules/wpScriptModules.php | 33 ------------------- tools/webpack/packages.js | 2 -- 7 files changed, 4 insertions(+), 67 deletions(-) diff --git a/package-lock.json b/package-lock.json index f392e9064e327..6c7e6840f985f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -79,7 +79,6 @@ "clipboard": "2.0.11", "core-js-url-browser": "3.6.4", "element-closest": "^3.0.2", - "es-module-shims": "1.8.2", "formdata-polyfill": "4.0.10", "hoverintent": "2.2.1", "imagesloaded": "5.0.0", @@ -14115,11 +14114,6 @@ "integrity": "sha512-vZK7T0N2CBmBOixhmjdqx2gWVbFZ4DXZ/NyRMZVlJXPa7CyFS+/a4QQsDGDQy9ZfEzxFuNEsMLeQJnKP2p5/JA==", "dev": true }, - "node_modules/es-module-shims": { - "version": "1.8.2", - "resolved": "https://registry.npmjs.org/es-module-shims/-/es-module-shims-1.8.2.tgz", - "integrity": "sha512-7vIYVzpOhXtpc3Yn03itB+GSgVZFW7oL4kdydA+iL+IEi7HiSLBUxM05QFw4SxTl6e++pMpGqZPo2+vdNs3TbA==" - }, "node_modules/es-object-atoms": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.0.0.tgz", @@ -44753,11 +44747,6 @@ "integrity": "sha512-vZK7T0N2CBmBOixhmjdqx2gWVbFZ4DXZ/NyRMZVlJXPa7CyFS+/a4QQsDGDQy9ZfEzxFuNEsMLeQJnKP2p5/JA==", "dev": true }, - "es-module-shims": { - "version": "1.8.2", - "resolved": "https://registry.npmjs.org/es-module-shims/-/es-module-shims-1.8.2.tgz", - "integrity": "sha512-7vIYVzpOhXtpc3Yn03itB+GSgVZFW7oL4kdydA+iL+IEi7HiSLBUxM05QFw4SxTl6e++pMpGqZPo2+vdNs3TbA==" - }, "es-object-atoms": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.0.0.tgz", diff --git a/package.json b/package.json index 49d03a9ed3be8..a9d59940de743 100644 --- a/package.json +++ b/package.json @@ -148,7 +148,6 @@ "clipboard": "2.0.11", "core-js-url-browser": "3.6.4", "element-closest": "^3.0.2", - "es-module-shims": "1.8.2", "formdata-polyfill": "4.0.10", "hoverintent": "2.2.1", "imagesloaded": "5.0.0", diff --git a/src/wp-includes/class-wp-script-modules.php b/src/wp-includes/class-wp-script-modules.php index f05e2ef3a879b..136cc332ab443 100644 --- a/src/wp-includes/class-wp-script-modules.php +++ b/src/wp-includes/class-wp-script-modules.php @@ -236,20 +236,6 @@ public function print_script_module_preloads() { public function print_import_map() { $import_map = $this->get_import_map(); if ( ! empty( $import_map['imports'] ) ) { - global $wp_scripts; - if ( isset( $wp_scripts ) ) { - wp_print_inline_script_tag( - wp_get_script_polyfill( - $wp_scripts, - array( - 'HTMLScriptElement.supports && HTMLScriptElement.supports("importmap")' => 'wp-polyfill-importmap', - ) - ), - array( - 'id' => 'wp-load-polyfill-importmap', - ) - ); - } wp_print_inline_script_tag( wp_json_encode( $import_map, JSON_HEX_TAG | JSON_HEX_AMP ), array( diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 0c71a1b3b0b1c..823160427ba61 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -96,7 +96,6 @@ function wp_default_packages_vendor( $scripts ) { 'lodash', 'wp-polyfill-fetch', 'wp-polyfill-formdata', - 'wp-polyfill-importmap', 'wp-polyfill-node-contains', 'wp-polyfill-url', 'wp-polyfill-dom-rect', @@ -122,7 +121,6 @@ function wp_default_packages_vendor( $scripts ) { 'wp-polyfill-object-fit' => '2.3.5', 'wp-polyfill-inert' => '3.1.2', 'wp-polyfill' => '3.15.0', - 'wp-polyfill-importmap' => '1.8.2', ); foreach ( $vendor_scripts as $handle => $dependencies ) { diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 203066998dd42..485dc9f34580e 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -3117,9 +3117,9 @@ public function test_wp_scripts_move_to_footer( $set_up, $expected_header, $expe */ public function test_wp_get_script_polyfill() { global $wp_scripts; - $script_name = 'wp-polyfill-importmap'; - $test_script = 'HTMLScriptElement.supports && HTMLScriptElement.supports("importmap")'; - $script_url = 'https://example.com/wp-polyfill-importmap.js'; + $script_name = 'tmp-polyfill-foo'; + $test_script = 'HTMLScriptElement.supports && HTMLScriptElement.supports("foo")'; + $script_url = 'https://example.com/polyfill-foo.js'; wp_register_script( $script_name, $script_url ); $polyfill = wp_get_script_polyfill( @@ -3133,7 +3133,7 @@ public function test_wp_get_script_polyfill() { $expected = '( ' . $test_script . ' ) || document.write( \'