1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Ensure monaco exists before attempting cleanup

This commit is contained in:
Steve-Mcl 2021-05-04 09:03:35 +01:00
parent ffbd140a97
commit 22db24509d

View File

@ -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 || {};