Make WordPress Core


Ignore:
Timestamp:
01/31/2024 08:29:18 AM (3 years ago)
Author:
gziolo
Message:

Script Modules API: Add import map polyfill for older browsers

Syncs the changes from https://github.com/WordPress/gutenberg/pull/58263. Adds a polyfill to make import maps compatible with unsported browsers (https://caniuse.com/import-maps).

Fixes #60348.
Props cbravobernal, jorbin, luisherranz, jonsurrell.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-script-modules.php

    r57345 r57492  
    212212         *
    213213         * @since 6.5.0
     214         *
     215         * @global WP_Scripts $wp_scripts The WP_Scripts object for printing the polyfill.
    214216         */
    215217        public function print_import_map() {
    216218                $import_map = $this->get_import_map();
    217219                if ( ! empty( $import_map['imports'] ) ) {
     220                        global $wp_scripts;
     221                        if ( isset( $wp_scripts ) ) {
     222                                wp_print_inline_script_tag(
     223                                        wp_get_script_polyfill(
     224                                                $wp_scripts,
     225                                                array(
     226                                                        'HTMLScriptElement.supports && HTMLScriptElement.supports("importmap")' => 'wp-polyfill-importmap',
     227                                                )
     228                                        ),
     229                                        array(
     230                                                'id' => 'wp-load-polyfill-importmap',
     231                                        )
     232                                );
     233                        }
    218234                        wp_print_inline_script_tag(
    219235                                wp_json_encode( $import_map, JSON_HEX_TAG | JSON_HEX_AMP ),
Note: See TracChangeset for help on using the changeset viewer.