Skip to content

Commit 176b14f

Browse files
committed
fix(Util): getScripts also need to reorder core translations
Currently `core-common` and `core-main` are prepanded to the scripts, as they provide the global state. But the script ordering logic does not know about this and might sort core translations after they are used. Meaning we need to register core translations as soon as the global scope is initialized (so that `OC.L10N.register` is available). Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent e761005 commit 176b14f

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

lib/public/Util.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,21 @@ public static function getScripts(): array {
168168
// Flatten array and remove duplicates
169169
$sortedScripts = array_merge([self::$scriptsInit], $sortedScripts);
170170
$sortedScripts = array_merge(...array_values($sortedScripts));
171+
$sortedScripts = array_unique($sortedScripts);
171172

172173
// Override core-common and core-main order
173-
if (in_array('core/js/main', $sortedScripts)) {
174-
array_unshift($sortedScripts, 'core/js/main');
175-
}
176-
if (in_array('core/js/common', $sortedScripts)) {
177-
array_unshift($sortedScripts, 'core/js/common');
174+
function scriptOrder(string $name) {
175+
return match($name) {
176+
'core/js/common' => 3,
177+
'core/js/main' => 2,
178+
default => str_starts_with($name, 'core/l10n/')
179+
? 1 // core translations have to be loaded directly after core-main
180+
: 0, // other scripts should preserve their current order
181+
};
178182
}
179183

180-
return array_unique($sortedScripts);
184+
usort($sortedScripts, fn (string $a, string $b) => scriptOrder($b) <=> scriptOrder($a));
185+
return $sortedScripts;
181186
}
182187

183188
/**

0 commit comments

Comments
 (0)