Skip to content

Commit 522e03a

Browse files
authored
Merge pull request #59643 from nextcloud/backport/59518/stable33
[stable33] fix(Util): `getScripts` also need to reorder core translations
2 parents 50a72bf + 1dc5215 commit 522e03a

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

lib/public/Util.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,27 @@ public static function getScripts(): array {
188188
// Flatten array and remove duplicates
189189
$sortedScripts = array_merge([self::$scriptsInit], $sortedScripts);
190190
$sortedScripts = array_merge(...array_values($sortedScripts));
191+
$sortedScripts = array_unique($sortedScripts);
191192

192-
// Override core-common and core-main order
193-
if (in_array('core/js/main', $sortedScripts)) {
194-
array_unshift($sortedScripts, 'core/js/main');
195-
}
196-
if (in_array('core/js/common', $sortedScripts)) {
197-
array_unshift($sortedScripts, 'core/js/common');
198-
}
193+
usort($sortedScripts, fn (string $a, string $b) => self::scriptOrderValue($b) <=> self::scriptOrderValue($a));
194+
return $sortedScripts;
195+
}
199196

200-
return array_unique($sortedScripts);
197+
/**
198+
* Gets a numeric value based on the script name.
199+
* This is used to ensure that the global state is initialized before all other scripts.
200+
*
201+
* @param string $name - The script name
202+
* @since 33.0.3
203+
*/
204+
private static function scriptOrderValue(string $name): int {
205+
return match($name) {
206+
'core/js/common' => 3,
207+
'core/js/main' => 2,
208+
default => str_starts_with($name, 'core/l10n/')
209+
? 1 // core translations have to be loaded directly after core-main
210+
: 0, // other scripts should preserve their current order
211+
};
201212
}
202213

203214
/**

0 commit comments

Comments
 (0)