Race condition: ckeditor initialized before files are loaded.
In ckeditor5/js/wysiwyg/crm.ckeditor5.js, the ckeditor and elfinder scripts are loaded and then initialized with the statement:
CRM.loadScript(CRM.config.CKEditor5Location).done(CRM.loadScript(CRM.config.ELFinderLocation).done(initialize));
When tested with a slow-loading script (I encountered this while testing with the CKeditor superbuild), I found that initialize could be called before ckeditor.js was loaded. This occurs because:
- It appears that the last closing parenthesis is not in the intended location. It presumably should have closed the first .done rather than the second .done.
- .done returns the same deferred object that called it, not its own return value. initialize therefore executes immediately after the elfinder script is queued to be loaded, and this can be before even the ckeditor script has loaded.
- The first .done is passed a value (the return of LoadScript, or the return of Loadscript.done as it is written) rather than a function as is required.
Replacing the above with the following ensures that initialize is not called until the deferreds from both calls to CRM.loadScript have been resolved:
$.when(
CRM.loadScript(CRM.config.CKEditor5Location),
CRM.loadScript(CRM.config.ELFinderLocation)
).done(initialize);
A similar correction is required also for the following line:
CRM.loadScript(CRM.config.CKEditor5Language).done(CRM.loadScript(CRM.config.CKEditor5Location).done(CRM.loadScript(CRM.config.ELFinderLocation).done(initialize)));