# Msg replayed in UI node after a tab switch

**URL:** https://discourse.nodered.org/t/msg-replayed-in-ui-node-after-a-tab-switch/25032
**Category:** Developing Nodes
**Created:** [17 April 2020 20:03 UTC](https://discourse.nodered.org/t/msg-replayed-in-ui-node-after-a-tab-switch/25032 "2020-04-17T20:03:49Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [17 April 2020 20:03 UTC](https://discourse.nodered.org/t/msg-replayed-in-ui-node-after-a-tab-switch/25032/1 "2020-04-17T20:03:49Z")

</div>

Hi folks,

some time ago @Thierry has created a very useful [pull request](https://github.com/node-red/node-red-dashboard/pull/558) to add the _ **persistantFrontEndValue** _ property to the addWidget function.

That new property has helped me already a lot in some of my UI nodes to avoid that the last input message is automatically replayed again _ **after a dashboard page refresh** _. For example in the node-red-contrib-ui-contextmenu node. Otherwise e.g. the last contextmenu would popup automatically after a page refresh, but currently it works fine:

![contextmenu_refresh](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/8/c8148250df8e339410948fe35c03d36494d21e7d.gif)

However the last message is still being replayed automatically _ **after a dashboard tab switch** _. As a result the last contextmenu appears again after a tab switch:

![contextmenu_tabswitch](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/2/b289984cf12dc61b1f83b51342b7a691bf91c89c.gif)

Thierry do you perhaps have any advice about how I could workaround this?

Thanks a lot!!!  
Bart

---

<div class="post-metadata">

### Author: ![nrbrt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nrbrt/32/11738_2.png) [@nrbrt](https://discourse.nodered.org/u/nrbrt)
#### Post date: [30 April 2020 05:25 UTC](https://discourse.nodered.org/t/msg-replayed-in-ui-node-after-a-tab-switch/25032/2 "2020-04-30T05:25:25Z")

</div>

Not only the last contextmenu appears after a tab switch, but every contextmenu that was ever opened appears after a tab switch. It is also a cumulative effect. You open one, switch tabs, one appears. You open a second one (after the first one closed automatically after a set timeout), switch tabs, 2 appear and so on. I really hope this can be fixed.

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [30 April 2020 16:50 UTC](https://discourse.nodered.org/t/msg-replayed-in-ui-node-after-a-tab-switch/25032/3 "2020-04-30T16:50:52Z")

</div>

That id indeed verh inconvenient. Will need to find some time then to figure out why the dashboard's _ **persistantFrontEndValue** _ doesn't work in that case...

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [1 May 2020 07:16 UTC](https://discourse.nodered.org/t/msg-replayed-in-ui-node-after-a-tab-switch/25032/4 "2020-05-01T07:16:09Z")

</div>

I have the impression that this is caused pure on the client-side.

1. I click on a shape in the SVG node, and the contextmenu appears. Indeed now I arrive on all my breakpoints (in the dashboard's ui.js file) on the server side, and the message is not added to the replayMessage array. So the _ **persistantFrontEndValue** _ parameter seems to do the job well.

2. I switch to another dashboard tabsheet

3. I switch back to the original tabsheet where my svg & contextmenu is located. At that moment I indeed get again a message on the client:

But I didn't arrive on my server-side breakpoints. So it seems that somehow the client replays the messages. I have installed today the dashboard from source code, because I hoped to be able to debug the main.js file. But from the call stack (see above screenshot) I only see minified stuff 🥴

Does anybody have a clue how I could try to find the root cause?  
Because I'm stuck at the moment ...

---

<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: [1 May 2020 08:42 UTC](https://discourse.nodered.org/t/msg-replayed-in-ui-node-after-a-tab-switch/25032/5 "2020-05-01T08:42:03Z")

</div>

Hi @BartButenaers .

I cant figure it out either but adding this slight hack seems to contain it...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/e/deefd3fbc35bd3752cc5f9337791834e65249f02.png)

```auto
if(msg._ui_cm_already_seen){
  console.log("ui_context_menu: msg already seen - exiting!")
  return;
}
msg._ui_cm_already_seen = true;

```

---

<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: [1 May 2020 08:51 UTC](https://discourse.nodered.org/t/msg-replayed-in-ui-node-after-a-tab-switch/25032/6 "2020-05-01T08:51:24Z")

</div>

@nrbrt would you be willing to test this?

If you could find a file named `context_menu.js` in your node-red folder like this.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/e/de12d7bb5d93ca528fbb5fff234d8ba8bfc5fad6.png)

- Open `context_menu.js` in a text editor
- Paste the code (in previous post) the as shown in the image (above)
- Save `context_menu.js`
- Restart node-red

It would be most helpful for you to test this.

the modification works for me but I will have different hardware, different flow, different browser, different OS, etc etc.

Let us know.

Cheers.  
It will be under

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [1 May 2020 10:25 UTC](https://discourse.nodered.org/t/msg-replayed-in-ui-node-after-a-tab-switch/25032/7 "2020-05-01T10:25:48Z")

</div>

> [@Steve-Mcl](#):
>
> if(msg.\_ui\_cm\_already\_seen){ console.log("ui\_context\_menu: msg already seen - exiting!") return; } msg.\_ui\_cm\_already\_seen = true;

Oh my god.  
I tried this a few months ago with the original replay problem, but it didn't work at the time being. Indeed because when the server replays the messages, it has no use to change the message on the client (since you get the original unchanged from the server). But if the client replays it, this little trick indeed seems a good workaround. After debugging the whole flow this morning, it seems I was brain dead at the moment I had figured out that the client caused the replay 🥴  
Nice catch!!

---

<div class="post-metadata">

### Author: ![nrbrt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nrbrt/32/11738_2.png) [@nrbrt](https://discourse.nodered.org/u/nrbrt)
#### Post date: [1 May 2020 11:29 UTC](https://discourse.nodered.org/t/msg-replayed-in-ui-node-after-a-tab-switch/25032/8 "2020-05-01T11:29:46Z")

</div>

Ofcourse I am willing to test it. I am on it now and will keep you posted.  
Thanks alot for your effort!

---

<div class="post-metadata">

### Author: ![nrbrt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nrbrt/32/11738_2.png) [@nrbrt](https://discourse.nodered.org/u/nrbrt)
#### Post date: [1 May 2020 11:37 UTC](https://discourse.nodered.org/t/msg-replayed-in-ui-node-after-a-tab-switch/25032/9 "2020-05-01T11:37:09Z")

</div>

It works like a charm! That is truly awesome!

---

<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: [1 May 2020 11:49 UTC](https://discourse.nodered.org/t/msg-replayed-in-ui-node-after-a-tab-switch/25032/10 "2020-05-01T11:49:45Z")

</div>

Thanks for testing.

@BartButenaers, I'll update the repo and publish an update to NPM of you have no objections.

---

<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: [1 May 2020 19:01 UTC](https://discourse.nodered.org/t/msg-replayed-in-ui-node-after-a-tab-switch/25032/11 "2020-05-01T19:01:42Z")

</div>

Hi, I have published an update that contains this fix.

Good catch.

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [1 May 2020 19:40 UTC](https://discourse.nodered.org/t/msg-replayed-in-ui-node-after-a-tab-switch/25032/12 "2020-05-01T19:40:57Z")

</div>

Thanks Steve!!

---

<div class="post-metadata">

### Author: ![Thierry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thierry/32/8654_2.png) [@Thierry](https://discourse.nodered.org/u/Thierry)
#### Post date: [19 May 2020 16:22 UTC](https://discourse.nodered.org/t/msg-replayed-in-ui-node-after-a-tab-switch/25032/13 "2020-05-19T16:22:30Z")

</div>

Hi @BartButenaers,

Sorry for not responding before but I've been very busy on other projects since several weeks or so...  
Fortunately it seems you have found a solution to your problem so that's fine.

From what I understand in this thread, you solved it by telling to the client to do nothing if same msg appears again in scope.watch, that's fine but still I don't understand why this msg appears again ?

Nevertheless looking in the network debug panel from the browser, the _ **persistantFrontEndValue** _ seems to work as expected as the second msg doesn't seem to come from the socket connected to backend...

If someone knows what is really happening (why the client seems to generate this second msg) and could explain here, I would be happy to learn.

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [19 May 2020 16:39 UTC](https://discourse.nodered.org/t/msg-replayed-in-ui-node-after-a-tab-switch/25032/14 "2020-05-19T16:39:09Z")

</div>

> [@Thierry](#):
>
> that's fine but still I don't understand why this msg appears again

Hi Thierry,  
Indeed it is a workaround and not a fix. But it works fine since it is exactly the same msg instance over and over again.

---

<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: [18 July 2020 16:39 UTC](https://discourse.nodered.org/t/msg-replayed-in-ui-node-after-a-tab-switch/25032/15 "2020-07-18T16:39:10Z")

</div>

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