From ac4de4298320f0c2480b31fa851c3ecd30ff721e Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Tue, 3 Mar 2020 16:53:32 +0000 Subject: [PATCH] Scripts: Use core-js url as polyfill for window.URL. URL polyfill from the polyfill-library library is not spec-conformant, in a way which negatively impacts its usability for pending revisions to the block editor. Specifically, there were revisions to the implementation of the wp-url script to detect URL validity by relying on thrown errors from the URL constructor, but this specific behavior is not implemented in this version of the polyfill. There was another issue in r47238, which is that the test used to check whether the polyfill should be included is not accurate. This commit uses a different check and fixes the issue. Props aduth. Fixes: #49360. git-svn-id: https://develop.svn.wordpress.org/trunk@47416 602fd350-edb4-49c9-b593-d223f7449a82 --- package-lock.json | 5 +++++ package.json | 1 + src/wp-includes/script-loader.php | 4 ++-- tests/phpunit/tests/dependencies/scripts.php | 2 +- tools/webpack/packages.js | 4 ++-- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4071d3ced1..5eb18f3db4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5862,6 +5862,11 @@ } } }, + "core-js-url-browser": { + "version": "3.6.4", + "resolved": "https://registry.npmjs.org/core-js-url-browser/-/core-js-url-browser-3.6.4.tgz", + "integrity": "sha512-VCMkPikOVp5JXftTj0E3gPZNKa0exQX837KxyPcnMAKvImWG8+RbXwEHEGMjiNz+9Vl2YgutkVYOpq7iaSOt/Q==" + }, "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", diff --git a/package.json b/package.json index e86d885f9b..65e69dde1c 100644 --- a/package.json +++ b/package.json @@ -121,6 +121,7 @@ "@wordpress/wordcount": "2.7.0", "backbone": "1.4.0", "clipboard": "2.0.4", + "core-js-url-browser": "3.6.4", "element-closest": "^2.0.2", "formdata-polyfill": "3.0.13", "hoverintent": "2.2.1", diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index f354b9edf0..8f9ec7b428 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -100,7 +100,7 @@ function wp_default_packages_vendor( $scripts ) { 'wp-polyfill-fetch' => '3.0.0', 'wp-polyfill-formdata' => '3.0.12', 'wp-polyfill-node-contains' => '3.42.0', - 'wp-polyfill-url' => '3.42.0', + 'wp-polyfill-url' => '3.6.4', 'wp-polyfill-dom-rect' => '3.42.0', 'wp-polyfill-element-closest' => '2.0.2', 'wp-polyfill' => '7.4.4', @@ -126,8 +126,8 @@ function wp_default_packages_vendor( $scripts ) { array( '\'fetch\' in window' => 'wp-polyfill-fetch', 'document.contains' => 'wp-polyfill-node-contains', - 'window.URL' => 'wp-polyfill-url', 'window.DOMRect' => 'wp-polyfill-dom-rect', + 'window.URL && window.URL.prototype && window.URLSearchParams' => 'wp-polyfill-url', 'window.FormData && window.FormData.prototype.keys' => 'wp-polyfill-formdata', 'Element.prototype.matches && Element.prototype.closest' => 'wp-polyfill-element-closest', ) diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 5b885fe1b2..b3d02c129c 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -717,7 +717,7 @@ JS; $expected .= "\n"; $expected .= "\n"; $expected .= "\n"; $expected .= "\n"; $expected .= "\n"; diff --git a/tools/webpack/packages.js b/tools/webpack/packages.js index de6ed4a041..6867c47c91 100644 --- a/tools/webpack/packages.js +++ b/tools/webpack/packages.js @@ -77,7 +77,7 @@ module.exports = function( env = { environment: 'production', watch: false, buil 'wp-polyfill-fetch.js': 'whatwg-fetch/dist/fetch.umd.js', 'wp-polyfill-element-closest.js': 'element-closest/element-closest.js', 'wp-polyfill-node-contains.js': 'polyfill-library/polyfills/Node/prototype/contains/polyfill.js', - 'wp-polyfill-url.js': 'polyfill-library/polyfills/URL/polyfill.js', + 'wp-polyfill-url.js': 'core-js-url-browser/url.js', 'wp-polyfill-dom-rect.js': 'polyfill-library/polyfills/DOMRect/polyfill.js', 'wp-polyfill-formdata.js': 'formdata-polyfill/FormData.js', 'moment.js': 'moment/moment.js', @@ -89,6 +89,7 @@ module.exports = function( env = { environment: 'production', watch: false, buil 'lodash.min.js': 'lodash/lodash.min.js', 'wp-polyfill.min.js': '@babel/polyfill/dist/polyfill.min.js', 'wp-polyfill-formdata.min.js': 'formdata-polyfill/formdata.min.js', + 'wp-polyfill-url.min.js': 'core-js-url-browser/url.min.js', 'moment.min.js': 'moment/min/moment.min.js', 'react.min.js': 'react/umd/react.production.min.js', 'react-dom.min.js': 'react-dom/umd/react-dom.production.min.js', @@ -98,7 +99,6 @@ module.exports = function( env = { environment: 'production', watch: false, buil 'wp-polyfill-fetch.min.js': 'whatwg-fetch/dist/fetch.umd.js', 'wp-polyfill-element-closest.min.js': 'element-closest/element-closest.js', 'wp-polyfill-node-contains.min.js': 'polyfill-library/polyfills/Node/prototype/contains/polyfill.js', - 'wp-polyfill-url.min.js': 'polyfill-library/polyfills/URL/polyfill.js', 'wp-polyfill-dom-rect.min.js': 'polyfill-library/polyfills/DOMRect/polyfill.js', };