From 22db24509d6ceb5687c3c20ed061db7ea7c0b778 Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Tue, 4 May 2021 09:03:35 +0100 Subject: [PATCH] Ensure monaco exists before attempting cleanup --- .../src/js/ui/editors/code-editors/monaco.js | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) 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 || {};