From 6503498f0a97fbdc417735163c8f5057dd354cf8 Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Sat, 29 Jun 2024 18:14:54 +0100 Subject: [PATCH] Clean up orphaned editors closes #4820 --- .../src/js/ui/editors/code-editors/monaco.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 cbeecd512..b9f586944 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 @@ -165,7 +165,13 @@ 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 (!window.monaco) { return; } + const editors = window.monaco.editor.getEditors() + const orphanEditors = editors.filter(editor => editor && !document.body.contains(editor.getDomNode())) + orphanEditors.forEach(editor => { + editor.dispose(); + }); + 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++) { @@ -1124,6 +1130,7 @@ RED.editor.codeEditor.monaco = (function() { $(el).remove(); $(toolbarRow).remove(); + ed.dispose(); } ed.resize = function resize() {