WordPress.org

Make WordPress Core

Changeset 47416


Ignore:
Timestamp:
03/03/2020 04:53:32 PM (12 months ago)
Author:
jorgefilipecosta
Message:

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.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/package-lock.json

    r47408 r47416  
    58635863            }
    58645864        },
     5865        "core-js-url-browser": {
     5866            "version": "3.6.4",
     5867            "resolved": "https://registry.npmjs.org/core-js-url-browser/-/core-js-url-browser-3.6.4.tgz",
     5868            "integrity": "sha512-VCMkPikOVp5JXftTj0E3gPZNKa0exQX837KxyPcnMAKvImWG8+RbXwEHEGMjiNz+9Vl2YgutkVYOpq7iaSOt/Q=="
     5869        },
    58655870        "core-util-is": {
    58665871            "version": "1.0.2",
  • trunk/package.json

    r47408 r47416  
    122122        "backbone": "1.4.0",
    123123        "clipboard": "2.0.4",
     124        "core-js-url-browser": "3.6.4",
    124125        "element-closest": "^2.0.2",
    125126        "formdata-polyfill": "3.0.13",
  • trunk/src/wp-includes/script-loader.php

    r47355 r47416  
    101101        'wp-polyfill-formdata'        => '3.0.12',
    102102        'wp-polyfill-node-contains'   => '3.42.0',
    103         'wp-polyfill-url'             => '3.42.0',
     103        'wp-polyfill-url'             => '3.6.4',
    104104        'wp-polyfill-dom-rect'        => '3.42.0',
    105105        'wp-polyfill-element-closest' => '2.0.2',
     
    127127                '\'fetch\' in window' => 'wp-polyfill-fetch',
    128128                'document.contains'   => 'wp-polyfill-node-contains',
    129                 'window.URL'          => 'wp-polyfill-url',
    130129                'window.DOMRect'      => 'wp-polyfill-dom-rect',
     130                'window.URL && window.URL.prototype && window.URLSearchParams' => 'wp-polyfill-url',
    131131                'window.FormData && window.FormData.prototype.keys' => 'wp-polyfill-formdata',
    132132                'Element.prototype.matches && Element.prototype.closest' => 'wp-polyfill-element-closest',
  • trunk/tests/phpunit/tests/dependencies/scripts.php

    r47238 r47416  
    718718        $expected .= "<script type='text/javascript' src='/wp-includes/js/dist/vendor/wp-polyfill.min.js'></script>\n";
    719719        $expected .= "<script type='text/javascript'>\n";
    720         $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";
     720        $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";
    721721        $expected .= "</script>\n";
    722722        $expected .= "<script type='text/javascript' src='/wp-includes/js/dist/dom-ready.min.js'></script>\n";
  • trunk/tools/webpack/packages.js

    r47352 r47416  
    7878        'wp-polyfill-element-closest.js': 'element-closest/element-closest.js',
    7979        'wp-polyfill-node-contains.js': 'polyfill-library/polyfills/Node/prototype/contains/polyfill.js',
    80         'wp-polyfill-url.js': 'polyfill-library/polyfills/URL/polyfill.js',
     80        'wp-polyfill-url.js': 'core-js-url-browser/url.js',
    8181        'wp-polyfill-dom-rect.js': 'polyfill-library/polyfills/DOMRect/polyfill.js',
    8282        'wp-polyfill-formdata.js': 'formdata-polyfill/FormData.js',
     
    9090        'wp-polyfill.min.js': '@babel/polyfill/dist/polyfill.min.js',
    9191        'wp-polyfill-formdata.min.js': 'formdata-polyfill/formdata.min.js',
     92        'wp-polyfill-url.min.js': 'core-js-url-browser/url.min.js',
    9293        'moment.min.js': 'moment/min/moment.min.js',
    9394        'react.min.js': 'react/umd/react.production.min.js',
     
    99100        'wp-polyfill-element-closest.min.js': 'element-closest/element-closest.js',
    100101        'wp-polyfill-node-contains.min.js': 'polyfill-library/polyfills/Node/prototype/contains/polyfill.js',
    101         'wp-polyfill-url.min.js': 'polyfill-library/polyfills/URL/polyfill.js',
    102102        'wp-polyfill-dom-rect.min.js': 'polyfill-library/polyfills/DOMRect/polyfill.js',
    103103    };
Note: See TracChangeset for help on using the changeset viewer.