Skip to content

Commit 154ed40

Browse files
committed
Use script module for emoji-loader with settings exported via JSON
1 parent 2ac68e9 commit 154ed40

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/js/_enqueues/lib/emoji-loader.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
* @property {?Function} readyCallback
1515
*/
1616

17+
// For compatibility with other scripts that read from this global.
18+
window._wpemojiSettings = /** @type {WPEmojiSettings} */ (
19+
JSON.parse( document.getElementById( 'wp-emoji-settings' ).textContent )
20+
);
21+
1722
/**
1823
* Support tests.
1924
* @typedef SupportTests

src/wp-includes/formatting.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6137,8 +6137,18 @@ function _print_emoji_detection_script() {
61376137
}
61386138

61396139
wp_print_inline_script_tag(
6140-
sprintf( 'window._wpemojiSettings = %s;', wp_json_encode( $settings ) ) . "\n" .
6141-
file_get_contents( ABSPATH . WPINC . '/js/wp-emoji-loader' . wp_scripts_get_suffix() . '.js' )
6140+
wp_json_encode( $settings, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
6141+
array(
6142+
'id' => 'wp-emoji-settings',
6143+
'type' => 'application/json',
6144+
)
6145+
);
6146+
6147+
wp_print_inline_script_tag(
6148+
file_get_contents( ABSPATH . WPINC . '/js/wp-emoji-loader' . wp_scripts_get_suffix() . '.js' ),
6149+
array(
6150+
'type' => 'module',
6151+
)
61426152
);
61436153
}
61446154

0 commit comments

Comments
 (0)