From 79bfe6a353eebcd475adcc32e7f2ba633d1fda2e Mon Sep 17 00:00:00 2001 From: GogoVega <92022724+GogoVega@users.noreply.github.com> Date: Mon, 29 Sep 2025 10:23:48 +0200 Subject: [PATCH] Fix `onremove` is not called on a pure editor plugin --- .../editor-client/src/js/ui/palette-editor.js | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/palette-editor.js b/packages/node_modules/@node-red/editor-client/src/js/ui/palette-editor.js index c8e62890f..03231aa44 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/palette-editor.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/palette-editor.js @@ -1612,22 +1612,32 @@ RED.palette.editor = (function() { refreshUpdateStatus(); } + const pluginList = []; + Object.entries(entry.pluginSet).forEach(([key, set]) => { + if (set.plugins && set.plugins.length) { + // Adds ID of plugins that exist in the runtime + pluginList.push(...set.plugins.map((plugin) => plugin.id)); + } else { + // Adds ID of plugins that only exist in the editor + pluginList.push(key); + } + }); + // We assume that a plugin that implements onremove // cleans the editor accordingly of its left-overs. let found_onremove = true; - - let keys = Object.keys(entry.pluginSet); - keys.forEach((key) => { - let set = entry.pluginSet[key]; - for (let i=0; i { + const plugin = RED.plugins.getPlugin(id); + if (plugin) { + if (plugin.onremove && typeof plugin.onremove === 'function') { + try { + plugin.onremove(); + } catch (error) { + console.warn(`Error while calling 'onremove' for plugin '${id}': `, error); } + } else if (plugin.onadd && typeof plugin.onadd === 'function') { + // if there's no 'onadd', there shouldn't be any left-overs + found_onremove = false; } } });