# Function node not removing Monaco models on delete

**URL:** <https://discourse.nodered.org/t/function-node-not-removing-monaco-models-on-delete/88408>\
**Category:** Core Development\
**Created:** [31 May 2024 11:07 UTC](https://discourse.nodered.org/t/function-node-not-removing-monaco-models-on-delete/88408 "2024-05-31T11:07:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![malee](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@malee](https://discourse.nodered.org/u/malee)\
**Post date:** [31 May 2024 11:07 UTC](https://discourse.nodered.org/t/function-node-not-removing-monaco-models-on-delete/88408/1 "2024-05-31T11:07:35Z")

</div>

After just adding an `oneditdelete` function to destroy and delete the editor after use. I noticed that the function node included with Node-RED does not do the same thing.

Not sure if it worth creating a PR over.

As you can see when a function node in use in a flow is deleted the following warning is visible within the developer console.

 ![Screenshot 2024-05-31 120628](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/6/66db86dd4c6d565449a8fa6e95b7fe7a5b081e35.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [31 May 2024 11:23 UTC](https://discourse.nodered.org/t/function-node-not-removing-monaco-models-on-delete/88408/2 "2024-05-31T11:23:43Z")

</div>

> [@malee](#):
>
> As you can see when a function node in use in a flow is deleted the following warning is visible within the developer console.
> 
> ![Screenshot 2024-05-31 120628](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/6/66db86dd4c6d565449a8fa6e95b7fe7a5b081e35.png)

The warning message occurs whenever an editor is closed and it detects orphaned models.

I know (and have just checked in case of a regression) that the core function node (`nodes/core/function/10-function.html`) does indeed call `.destroy()` in both `oneditcancel` and `oneditsave`).

However, there may be a timing issue. Since there is more than 1 model to destroy, the destruction of the first may inadvertently be detecting the (as yet) still un-destroyed models.

Feel free to investigate and offer a PR if you find the cause is inside Node-RED (and not some other node)

PS: That code is in `editor-client/src/js/ui/editors/code-editors/monaco.js` around line 165 (search for "//Handles orphaned models")

---

<div class="post-metadata">

**Author:** ![malee](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@malee](https://discourse.nodered.org/u/malee)\
**Post date:** [31 May 2024 11:28 UTC](https://discourse.nodered.org/t/function-node-not-removing-monaco-models-on-delete/88408/3 "2024-05-31T11:28:16Z")

</div>

> [@Steve-Mcl](#):
>
> I know (and have just checked in case of a regression) that the core function node (`nodes/core/function/10-function.html`) does indeed call `.destroy()` in both `oneditcancel` and `oneditsave`).

This is what a node we have developed does, I found the warning was when I deleted the node, to remove the warning I had to add this to the `oneditdelete` function.

```auto
oneditdelete: function () {
     if (!this.editor) {
	return;
     }
    this.editor.destroy();
    delete this.editor;
},

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [29 August 2024 11:28 UTC](https://discourse.nodered.org/t/function-node-not-removing-monaco-models-on-delete/88408/4 "2024-08-29T11:28:44Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
