Skip to content

Commit

Permalink
Script Loader: Remove importmap polyfill.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
swissspidy committed Aug 29, 2024
1 parent 0a9dcb4 commit 35f8213
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 67 deletions.
11 changes: 0 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 0 additions & 14 deletions src/wp-includes/class-wp-script-modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 0 additions & 2 deletions src/wp-includes/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 ) {
Expand Down
8 changes: 4 additions & 4 deletions tests/phpunit/tests/dependencies/scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -3133,7 +3133,7 @@ public function test_wp_get_script_polyfill() {

$expected = '( ' . $test_script . ' ) || document.write( \'<script src="' . $script_url . '"></scr\' + \'ipt>\' );';

$this->assertEquals( $expected, $polyfill );
$this->assertSame( $expected, $polyfill );
}

/**
Expand Down
33 changes: 0 additions & 33 deletions tests/phpunit/tests/script-modules/wpScriptModules.php
Original file line number Diff line number Diff line change
Expand Up @@ -700,39 +700,6 @@ public function test_wp_enqueue_script_module_registers_all_params() {
$this->assertStringStartsWith( '/dep.js', $import_map['dep'] );
}

/**
* @ticket 60348
*
* @covers ::print_import_map_polyfill()
*/
public function test_wp_print_import_map_has_no_polyfill_when_no_modules_registered() {
$import_map_polyfill = get_echo( array( $this->script_modules, 'print_import_map' ) );

$this->assertSame( '', $import_map_polyfill );
}

/**
* @ticket 60348
*
* @covers ::print_import_map_polyfill()
*/
public function test_wp_print_import_map_has_polyfill_when_modules_registered() {
$script_name = 'wp-polyfill-importmap';
wp_register_script( $script_name, '/wp-polyfill-importmap.js' );

$this->script_modules->enqueue( 'foo', '/foo.js', array( 'dep' ), '1.0' );
$this->script_modules->register( 'dep', '/dep.js' );
$import_map_polyfill = get_echo( array( $this->script_modules, 'print_import_map' ) );

wp_deregister_script( $script_name );

$p = new WP_HTML_Tag_Processor( $import_map_polyfill );
$p->next_tag( array( 'tag' => 'SCRIPT' ) );
$id = $p->get_attribute( 'id' );

$this->assertSame( 'wp-load-polyfill-importmap', $id );
}

/**
* @ticket 61510
*/
Expand Down
2 changes: 0 additions & 2 deletions tools/webpack/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ module.exports = function (
'wp-polyfill-object-fit.js':
'objectFitPolyfill/src/objectFitPolyfill.js',
'wp-polyfill-inert.js': 'wicg-inert/dist/inert.js',
'wp-polyfill-importmap.js': 'es-module-shims/dist/es-module-shims.wasm.js',
'moment.js': 'moment/moment.js',
'regenerator-runtime.js': 'regenerator-runtime/runtime.js',
'react.js': 'react/umd/react.development.js',
Expand Down Expand Up @@ -122,7 +121,6 @@ module.exports = function (
'polyfill-library/polyfills/__dist/Node.prototype.contains/raw.js',
'wp-polyfill-dom-rect.min.js':
'polyfill-library/polyfills/__dist/DOMRect/raw.js',
'wp-polyfill-importmap.min.js': 'es-module-shims/dist/es-module-shims.wasm.js',
};

const phpFiles = {
Expand Down

0 comments on commit 35f8213

Please sign in to comment.