Merge pull request #59643 from nextcloud/backport/59518/stable33

[stable33] fix(Util): `getScripts` also need to reorder core translations
This commit is contained in:
Ferdinand Thiessen 2026-04-15 14:20:30 +02:00 committed by GitHub
commit 522e03a605
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -188,16 +188,27 @@ class Util {
// Flatten array and remove duplicates
$sortedScripts = array_merge([self::$scriptsInit], $sortedScripts);
$sortedScripts = array_merge(...array_values($sortedScripts));
$sortedScripts = array_unique($sortedScripts);
// Override core-common and core-main order
if (in_array('core/js/main', $sortedScripts)) {
array_unshift($sortedScripts, 'core/js/main');
}
if (in_array('core/js/common', $sortedScripts)) {
array_unshift($sortedScripts, 'core/js/common');
}
usort($sortedScripts, fn (string $a, string $b) => self::scriptOrderValue($b) <=> self::scriptOrderValue($a));
return $sortedScripts;
}
return array_unique($sortedScripts);
/**
* Gets a numeric value based on the script name.
* This is used to ensure that the global state is initialized before all other scripts.
*
* @param string $name - The script name
* @since 33.0.3
*/
private static function scriptOrderValue(string $name): int {
return match($name) {
'core/js/common' => 3,
'core/js/main' => 2,
default => str_starts_with($name, 'core/l10n/')
? 1 // core translations have to be loaded directly after core-main
: 0, // other scripts should preserve their current order
};
}
/**