File tree Expand file tree Collapse file tree 1 file changed +19
-8
lines changed
Expand file tree Collapse file tree 1 file changed +19
-8
lines changed Original file line number Diff line number Diff 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 /**
You can’t perform that action at this time.
0 commit comments