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
This commit is contained in:
Jorge Costa 2020-03-03 16:53:32 +00:00
parent 360c98280c
commit ac4de42983
5 changed files with 11 additions and 5 deletions

5
package-lock.json generated
View File

@ -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",

View File

@ -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",

View File

@ -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',
)

View File

@ -717,7 +717,7 @@ JS;
$expected .= "<script type='text/javascript' src='http://example.com'></script>\n";
$expected .= "<script type='text/javascript' src='/wp-includes/js/dist/vendor/wp-polyfill.min.js'></script>\n";
$expected .= "<script type='text/javascript'>\n";
$expected .= "( 'fetch' in window ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-fetch.min.js\"></scr' + 'ipt>' );( document.contains ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-node-contains.min.js\"></scr' + 'ipt>' );( window.URL ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-url.min.js\"></scr' + 'ipt>' );( window.DOMRect ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-dom-rect.min.js\"></scr' + 'ipt>' );( window.FormData && window.FormData.prototype.keys ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-formdata.min.js\"></scr' + 'ipt>' );( Element.prototype.matches && Element.prototype.closest ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-element-closest.min.js\"></scr' + 'ipt>' );\n";
$expected .= "( 'fetch' in window ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-fetch.min.js\"></scr' + 'ipt>' );( document.contains ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-node-contains.min.js\"></scr' + 'ipt>' );( window.DOMRect ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-dom-rect.min.js\"></scr' + 'ipt>' );( window.URL && window.URL.prototype && window.URLSearchParams ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-url.min.js\"></scr' + 'ipt>' );( window.FormData && window.FormData.prototype.keys ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-formdata.min.js\"></scr' + 'ipt>' );( Element.prototype.matches && Element.prototype.closest ) || document.write( '<script src=\"http://example.org/wp-includes/js/dist/vendor/wp-polyfill-element-closest.min.js\"></scr' + 'ipt>' );\n";
$expected .= "</script>\n";
$expected .= "<script type='text/javascript' src='/wp-includes/js/dist/dom-ready.min.js'></script>\n";
$expected .= "<script type='text/javascript' src='/wp-includes/js/dist/a11y.min.js'></script>\n";

View File

@ -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',
};