XF 2.0 Quick Thread & Javascript Loading

Lukas W.

Well-known member
I'm currently trying to fight a bug in my Editor Manager that appears on the quick thread option.

The console prints the following:
MqYbtfF.png

You can check it out here: http://fading-colors.com/dev/forums/main-forum.2/ - login credentials are user/user.

As far as I have been able to figure it out, it seems that my two injected scripts are executed too early in the chain and the editor that I am trying to extend has not yet been loaded. I'd might be able to hack around it for my own script, however I doubt I can deploy the froala table plugin later without modifying the file, which I wouldn't like to do.
The printed load order of the scripts seems to vary, sometimes they load from bottom to top as seen above, sometimes the other way round. There are also occassions where only the errors are printed to the console and details about the loaded scripts are completely missing. But no matter how they are printed to the console, the errors keep popping up. I guess the order in which they are executed is not correct or does overlap. There also have been one or two occassins where it worked though... I am really clueless on how to tackle that problem.
 
Traditionally, dynamic/asynchronously-loaded scripts execute in a non-deterministic order, just whatever downloads first. We've had to workaround this in the past and I recall some difficulties in XF1 relating to this.

I have just rebuilt the script loader code and it is now able to respect the requested load order. This will be included in 2.0 beta 3.
 
@Mike thanks a lot for the work! It's a lot better already. There's only one inline script that's loaded to late, the rest is working perfectly.

HTML:
<xf:if is="{{ $em_templates }}">
    <script class="js-klEditorTemplates" type="application/json">
        {$em_templates|json|raw}
    </script>
    
    <xf:js src="addons/kl/editor-manager/templates.plugin.js" min="1" />
</xf:if>

The templates.plugin.js is trying to load the content of the $em_templates. Printing the content to the console returns 'undefined', which throws a JSON parse error. Looking up the HTML content does however show, that the content is properly set and manually querying via the console after triggering does return the right results. I guess I can work around that with a brief delay in the plugin loader - or at least I hope so.

I've noticed that the quick thread editor seems to load twice on very rare ocassions. There doesn't seem to be any specific trigger for it - at least I haven't been able to find it. I encountered it in about 2-3 of ~100 page reloads.
 
Despite using script tags, that's not actually script related -- it's really just a basic DOM element in that case.

But yes, HTML isn't inserted until after the scripts are loaded. You generally shouldn't be doing any work when the script is loaded. You'd normally want to trigger based on some other event (or do something conditional if other things have already been loaded). You may want to look at the xf:reinit event as one example. (Bear in mind that event can be called a number of times.)
 
I've managed to do a workaround by shifting the actual loading of the variable to the inside of the $.FE.RegisterCommand-function.
 
Top Bottom