Script Loader: Fix i18n edge case breaking dependencies.

Prevent concatenation of scripts if the text domain is defined to ensure the dependency order is respected.

This accounts for an edge case in which replacing a core script via a plugin and a lack of translations (eg, for a US English site) could cause the JavaScript files to be ordered incorrectly.

Follow up to [52937].

Props audrasjb, boniu91, chaion07, costdev, hellofromtonya, jsnajdr, mukesh27, ndiego, ugyensupport, SergeyBiryukov.
Merges [53360,53366] to the 6.0 branch.
Fixes #55628.


Built from https://develop.svn.wordpress.org/branches/6.0@53367


git-svn-id: http://core.svn.wordpress.org/branches/6.0@52956 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Peter Wilson 2022-05-09 00:03:18 +00:00
parent afa1841d32
commit 3ab07afe02
2 changed files with 8 additions and 2 deletions

View File

@ -311,6 +311,12 @@ class WP_Scripts extends WP_Dependencies {
$inline_script_tag = '';
}
/*
* Prevent concatenation of scripts if the text domain is defined
* to ensure the dependency order is respected.
*/
$translations_stop_concat = ! empty( $obj->textdomain );
$translations = $this->print_translations( $handle, false );
if ( $translations ) {
$translations = sprintf( "<script%s id='%s-js-translations'>\n%s\n</script>\n", $this->type_attr, esc_attr( $handle ), $translations );
@ -327,7 +333,7 @@ class WP_Scripts extends WP_Dependencies {
*/
$srce = apply_filters( 'script_loader_src', $src, $handle );
if ( $this->in_default_dir( $srce ) && ( $before_handle || $after_handle || $translations ) ) {
if ( $this->in_default_dir( $srce ) && ( $before_handle || $after_handle || $translations_stop_concat ) ) {
$this->do_concat = false;
// Have to print the so-far concatenated scripts right away to maintain the right order.

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.0-RC1-53361';
$wp_version = '6.0-RC1-53367';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.