defer initialization of Monaco and ACE editors until they are loaded

design-88-editor-loading-with-preload
Steve-Mcl 2026-03-02 17:49:12 +00:00
parent 865aa4f765
commit adf324c99c
3 changed files with 10 additions and 2 deletions

View File

@ -2321,7 +2321,6 @@ RED.editor = (function() {
}
return {
init: function() {
if(window.ace) { window.ace.config.set('basePath', 'vendor/ace'); }
RED.tray.init();
RED.actions.add("core:confirm-edit-tray", function() {
$(document.activeElement).blur();
@ -2333,7 +2332,6 @@ RED.editor = (function() {
$("#node-dialog-cancel").trigger("click");
$("#node-config-dialog-cancel").trigger("click");
});
RED.editor.codeEditor.init();
},
generateViewStateId: generateViewStateId,
edit: showEditDialog,

View File

@ -36,6 +36,15 @@
if (!selectedCodeEditor || (editorChoice === MONACO && (browser.ie || !window.monaco))) {
selectedCodeEditor = RED.editor.codeEditor[defaultEditor];
}
// On first uncached load, editor may not yet be downloaded and in the DOM, so we check for the presence in `window` and defer
// initialization until the editor is actually loaded. Not relevant for basic editor as it is always present.
if (editorChoice === MONACO && !window.monaco) {
console.debug("Monaco editor is not yet loaded, delaying initialization");
return
} else if (editorChoice === ACE && !window.ace) {
console.debug("ACE editor is not yet loaded, delaying initialization");
return
}
initialised = selectedCodeEditor.init();
} catch (error) {
selectedCodeEditor = null;

View File

@ -22,6 +22,7 @@ RED.editor.codeEditor.ace = (function() {
var initOptions = {};
function init(options) {
window.ace.config.set('basePath', 'vendor/ace');
initOptions = options || {};
initialised = true;
return initialised;