Discussion in 'Resolved Bug Reports' started by cclaerhout, Nov 4, 2013.
The issue isn't really clear. A simple test case to demonstrate the issue would help.
I suppose you're doing some sort of (order-dependent) extension/manipulation of the editor (or any other XF JS) object and that the expected load order isn't happening when dependencies are dynamically added. There's no guarantee of order for scripts that are dynamically loaded, just that they're all loaded. Adding an expected execution order is not in the scope of what we're trying to do.
The XF classes won't be instantiated until this happens so it's not obvious what the purpose of the setTimeout is (unless you're doing something on the same event).
May be there's another solution, I don't know. It's just working. I've no idea if the vocabulary I use is technically correct or not, it's just can be reproduced. Here's the code Time sent to me (to use in the XenPorta "EWRblock_RecentNews" template).
Now to come back to the idea of having a minimum control on the scripts loading orders, may be It's me and I don't see the way of achieving this, but since the way to extend your framework seems to be to load data before the framework script and since there's no way right now to control the execution order once an overlay is called, this might be a not very comfortable situation for independent developers.
One more thing, once again I don't know why, the problem is only available for phrases with the "Use Bb Code Editor" phrase (not others). With the setTimeout trick, the problem is not there anymore. The "for" is underline because I think if more parameters have to be loaded, some problems will also occur. This is what I've met in other situations.
This is fixed now. The XF classes were activated before inline JS was run; I've inverted this order now as it's more consistent with how it works for non-overlay triggers. I think this is the only scenario where it comes up.
Your title is effectively far more precise than mine. So the safest way to extend your framework is to use inline js? There's no other way to be sure that one of the two JS using the helper "require js" inside a same template will be loaded before the other one?
Well, the core issue that you're explaining -- the phrase text in the editor when loaded only via an overlay -- is simply related to inline JS vs xfActivate trigger order, which I've changed. If inline JS is not used (and in this case, it's only used for editor phrases), there won't be any change in behavior.
I'm not really stating anything about using inline script. If you have JS B that must run after A is loaded, you may need to look at ways to either change that or change how dependencies are loaded (not using the standard ExtLoader system). When we load external dependencies, we load them in parallel to be faster, so the execution order is indeterminate.
So to be a little more concrete for me, all js loaded with "require js" helper will be loaded with the ExtLoader (when an overlay is called), which means if I want to load a JS file before your Editor framework possible and safe solutions would be:
not to use this helper and use instead the "on" jquery function (with its former pattern live)
extend the XenForo.ExtLoader to match the custom js and reorder the array with it at the top
(edit) insert the js in the template directly since now with the fix it will be executed first
That doesn't sound super convenient but I will give it a try.
Separate names with a comma.