Skip to content

Commit 5668298

Browse files
authored
Merge pull request #1754 from FlowFuse/1079-removing-ui-control-node-instance-crash
Guard call to `wNode.send` to avoid unhandled exceptions when ui-control is removed
2 parents 619f1f4 + 0f387e1 commit 5668298

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

nodes/widgets/ui_control.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -364,21 +364,25 @@ module.exports = function (RED) {
364364
connection: function (conn) {
365365
if (config.events === 'all' || config.events === 'connect') {
366366
const wNode = RED.nodes.getNode(node.id)
367-
let msg = {
368-
payload: 'connect'
367+
if (wNode && typeof wNode.send === 'function') {
368+
let msg = {
369+
payload: 'connect'
370+
}
371+
msg = addConnectionCredentials(RED, msg, conn, ui)
372+
wNode.send(msg)
369373
}
370-
msg = addConnectionCredentials(RED, msg, conn, ui)
371-
wNode.send(msg)
372374
}
373375
},
374376
disconnect: function (conn) {
375377
if (config.events === 'all' || config.events === 'connect') {
376378
const wNode = RED.nodes.getNode(node.id)
377-
let msg = {
378-
payload: 'lost'
379+
if (wNode && typeof wNode.send === 'function') {
380+
let msg = {
381+
payload: 'lost'
382+
}
383+
msg = addConnectionCredentials(RED, msg, conn, ui)
384+
wNode.send(msg)
379385
}
380-
msg = addConnectionCredentials(RED, msg, conn, ui)
381-
wNode.send(msg)
382386
}
383387
},
384388
'ui-control': function (conn, id, evt, payload) {

0 commit comments

Comments
 (0)