New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
elgg_get_loaded_js() mangles order when priority is the same (Trac #3355) #3355
Comments
cash wrote on 41284306-01-06 If JS plugins requires a certain order, they should use the priority value (that's why it is there after all). The problem is that usort does not preserve original order for items that have the same sort value. This is occurring in both menu items and js/css registration. We could try to adding more logic to the sort function that checks original index for ties. |
brettp wrote on 41284320-08-27 Other systems (views, hooks, events) maintain registration order without needing to be explicit so I assumed this one would. That's the problem. Instead of adding more logic to the sort function, what if we keep a static variable in the registration function that increments if the priority isn't explicitly set. More efficient than additional comparisons? |
trac user lie2815 wrote on 41299418-07-02 So should this be fixed? If so, I'd like to do it. |
brettp wrote on 41299436-02-25 lie2815 - Yes, this should be fixed. Feel free to take care of it :) |
trac user lie2815 wrote on 41299454-10-25 Okay, will do. |
trac user lie2815 wrote on 41300233-05-17 Here's your pull request: |
trac user tomv wrote on 41384225-11-24 Maybe stupid thought... but an idea: before doing the usort, extend the array with an extra sequential number. And then usort on the combination of this number and the priority ;) |
trac user tomv wrote on 41384226-03-20 Maybe stupid thought... but an idea: before doing the usort, extend the array with an extra sequential number. And then usort on the combination of this number and the priority (if priority equal, than compare sequential number in usort function). In that way you don't need extra field. |
trac user tomv wrote on 41384232-02-21 Maybe stupid thought... but an idea: before doing the usort, extend the array with an extra sequential number. And then usort on the combination of this number and the priority (if priority equal, than compare sequential number in usort function). In that way you don't need extra field. |
trac user tomv wrote on 41384287-01-21 Hm, the 3x posting was unintentional. But, decided to write a piece of code (without testing!) as a suggestion:
|
cash wrote on 41398236-07-14 I'm thinking that a better approach is solving this in the storage rather than on the sort side of things. Make the ordering explicit like it is for plugin hooks and views. |
ewinslow wrote on 41398602-01-24 Yea, I agree with Cash. It should be implemented the same way other subsystems are. Seems like we need a data structure for this (like I did for the javascript). |
trac user tomv wrote on 41399838-02-11 Fully agree. This was quick and dirty bug fix but seems that is not needed... |
cash wrote on 41497335-08-14 I'm thinking a dual index (priority and name). |
Original ticket http://trac.elgg.org/ticket/3355 on 41284286-08-03 by brettp, assigned to unknown.
Elgg version: Github Master
I couldn't quickly duplicate this in the unit test, but it's happening on my install in practice. Here is the loaded js in elgg_get_loaded_external_files() before the usort():
And here it is after the usort:
It looks like we'll need to add more info for the usort to include load order. The solution is currently to manually specify priority for js that requires load order.
(Set at high because this is very problematic and a pain to debug if loading jquery plugins that require a specific order.)
The text was updated successfully, but these errors were encountered: