diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/editors/code-editors/monaco.js b/packages/node_modules/@node-red/editor-client/src/js/ui/editors/code-editors/monaco.js index 4c8b944a8..ebac20d39 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/editors/code-editors/monaco.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/editors/code-editors/monaco.js @@ -98,20 +98,6 @@ RED.editor.codeEditor.monaco = (function() { const defaultServerSideTypes = [ knownModules["node-red-util"], knownModules["node-red-func"], knownModules["globals"], knownModules["console"], knownModules["buffer"] ]; const modulesCache = {}; - - RED.events.on("editor:close",function() { - //catch all - when editor is closed, ensure lod models that are not explicitly destroyed by a call to .destroy() are dumped - let models = monaco.editor.getModels(); - if(models && models.length) { - console.warn("Cleaning up monaco models left behind. Any node that calls createEditor() should call .destroy().") - for (let index = 0; index < models.length; index++) { - const model = models[index]; - if(!model.isDisposed()) { - model.dispose(); - } - } - } - }); /** * Helper function to load/reload types. @@ -175,6 +161,21 @@ RED.editor.codeEditor.monaco = (function() { } } }); + + //Handles orphaned models + //ensure loaded models that are not explicitly destroyed by a call to .destroy() are disposed + RED.events.on("editor:close",function() { + let models = window.monaco ? monaco.editor.getModels() : null; + if(models && models.length) { + console.warn("Cleaning up monaco models left behind. Any node that calls createEditor() should call .destroy().") + for (let index = 0; index < models.length; index++) { + const model = models[index]; + if(!model.isDisposed()) { + model.dispose(); + } + } + } + }); options = options || {}; window.MonacoEnvironment = window.MonacoEnvironment || {};