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 1/4] 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; } } }); From 7e4354aa56d34097260797632e1c789dca3894b7 Mon Sep 17 00:00:00 2001 From: GogoVega <92022724+GogoVega@users.noreply.github.com> Date: Tue, 30 Sep 2025 18:53:05 +0200 Subject: [PATCH 2/4] Improvements + better comments --- .../editor-client/src/js/ui/palette-editor.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 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 03231aa44..bd428959d 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 @@ -1615,10 +1615,10 @@ RED.palette.editor = (function() { const pluginList = []; Object.entries(entry.pluginSet).forEach(([key, set]) => { if (set.plugins && set.plugins.length) { - // Adds ID of plugins that exist in the runtime + // Adds ID of plugins that exist in the runtime and possibly in the editor pluginList.push(...set.plugins.map((plugin) => plugin.id)); } else { - // Adds ID of plugins that only exist in the editor + // Adds plugin ID that only exist in the editor pluginList.push(key); } }); @@ -1629,16 +1629,20 @@ RED.palette.editor = (function() { pluginList.forEach((id) => { const plugin = RED.plugins.getPlugin(id); if (plugin) { - if (plugin.onremove && typeof plugin.onremove === 'function') { + if (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') { + } else if (typeof plugin.onadd === 'function') { // if there's no 'onadd', there shouldn't be any left-overs found_onremove = false; } + } else { + // Either the plugin exists only in the runtime or it is a known limitation + // of purely editor plugins which must have their ID identical to that + // defined in the package.json } }); From bc2153bcdf754bec0b9c5cd790b06ade27d0f152 Mon Sep 17 00:00:00 2001 From: GogoVega <92022724+GogoVega@users.noreply.github.com> Date: Thu, 9 Oct 2025 11:48:01 +0200 Subject: [PATCH 3/4] Update comments --- .../@node-red/editor-client/src/js/ui/palette-editor.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 bd428959d..b1f1ea79d 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 @@ -1636,8 +1636,11 @@ RED.palette.editor = (function() { console.warn(`Error while calling 'onremove' for plugin '${id}': `, error); } } else if (typeof plugin.onadd === 'function') { - // if there's no 'onadd', there shouldn't be any left-overs + // We assume that the plugin adds something to the editor but is not able to remove it + // Notify the user to refresh the editor to remove that plugin found_onremove = false; + } else { + // If there's no 'onadd', there shouldn't be any left-overs } } else { // Either the plugin exists only in the runtime or it is a known limitation From 141b14237da3f6096e49d019d696aadaf2e26410 Mon Sep 17 00:00:00 2001 From: GogoVega <92022724+GogoVega@users.noreply.github.com> Date: Thu, 9 Oct 2025 12:12:33 +0200 Subject: [PATCH 4/4] Rephrase the reload message --- .../@node-red/editor-client/locales/en-US/editor.json | 2 +- .../node_modules/@node-red/editor-client/locales/fr/editor.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/locales/en-US/editor.json b/packages/node_modules/@node-red/editor-client/locales/en-US/editor.json index c1c9316d8..9bba632f9 100644 --- a/packages/node_modules/@node-red/editor-client/locales/en-US/editor.json +++ b/packages/node_modules/@node-red/editor-client/locales/en-US/editor.json @@ -684,7 +684,7 @@ "title": "Remove nodes" }, "removePlugin": { - "body": "

Removed plugin __module__. Please reload the editor to clear left-overs.

" + "body": "

Removed plugin __module__. Please reload the editor to continue.

" }, "update": { "body": "

Updating '__module__'

Updating the node will require a restart of Node-RED to complete the update. This must be done manually.

", diff --git a/packages/node_modules/@node-red/editor-client/locales/fr/editor.json b/packages/node_modules/@node-red/editor-client/locales/fr/editor.json index a205002d9..8ad966f4d 100644 --- a/packages/node_modules/@node-red/editor-client/locales/fr/editor.json +++ b/packages/node_modules/@node-red/editor-client/locales/fr/editor.json @@ -682,7 +682,7 @@ "title": "Supprimer les noeuds" }, "removePlugin": { - "body": "

Suppression du plugin '__module__'. Veuillez recharger l'éditeur afin d'appliquer les changements.

" + "body": "

Suppression du plugin '__module__'. Veuillez recharger l'éditeur pour continuer.

" }, "update": { "body": "

Mise à jour de '__module__'

La mise à jour du noeud nécessitera un redémarrage de Node-RED pour terminer la mise à jour. Cela doit être fait manuellement.

",