# Refresh ui-node

**URL:** <https://discourse.nodered.org/t/refresh-ui-node/13921>\
**Category:** Dashboard\
**Created:** [2 August 2019 09:16 UTC](https://discourse.nodered.org/t/refresh-ui-node/13921 "2019-08-02T09:16:49Z")\
**Posts on this page:** 20\
**Page:** 2

<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:** [5 October 2019 18:39 UTC](https://discourse.nodered.org/t/refresh-ui-node/13921/21 "2019-10-05T18:39:12Z")

</div>

If I'm understanding this, we ignore any and all messages untill we receive our own?

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [5 October 2019 18:40 UTC](https://discourse.nodered.org/t/refresh-ui-node/13921/22 "2019-10-05T18:40:45Z")

</div>

Yep. The only message which can happen before init message is replaymessage. I tested slightly, it worked for me.

---

<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:** [5 October 2019 19:50 UTC](https://discourse.nodered.org/t/refresh-ui-node/13921/23 "2019-10-05T19:50:40Z")

</div>

Thanks for this.

@BartButenaers see ^

If I get time tomorrow, I'll push a fix for both nodes.

---

<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:** [5 October 2019 21:35 UTC](https://discourse.nodered.org/t/refresh-ui-node/13921/24 "2019-10-05T21:35:27Z")

</div>

> [@hotNipi](#):
>
> As you can not ignore first message always (it may be correct message) make your own first message

Hey @Steve-Mcl,  
I think we should give @hotNipi the Node-RED award for creativity this week 😉 Very simple workaround, so I got to love it ...

On the other hand, it is so pitty that we cannot handle this kind of stuff in the dashboard code (so all contributions could benefit from a standard solution). Did some debugging and I was almost close, but no sigar:

- As soon as an input message arrives, that input message is being stored (with the node id as key) in `replayMessages`:

- Immediately afterwards the '_ui-replay-state_' event is triggered, and the handler will get the message (for this node id from `replayMessages`) and send it to the browser:

- But when I **deploy** my flow, I again arrive in the same event handler. So the same message will be send to the browser here, _ **which is not what I want.** _👎

I don't see any way to avoid the ui-replay-state event being triggered, so I tried if I could remove the message from the `replayMessages` variable. When we call `addWidget` in our node, and I debug into that function I see that the `replayMessages` is indeed available in the ui.js:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/aca442979fdef96deac42f30e825c11a12587047.png)

When I execute (inside the `add` function) the following in my Chrome debugger console:

```auto
delete replayMessages[opt.node.id];

```

Then the event handler has no message to send to the browser (for the current node id), so no contextmenu appears, so problem solved.

@dceejay: is there any way we can access the `replayMessages` variable from our node (just before we call `addWidget`)? Here my Javascript knowledge suddenly ends ...

---

<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:** [5 October 2019 21:54 UTC](https://discourse.nodered.org/t/refresh-ui-node/13921/25 "2019-10-05T21:54:42Z")

</div>

Or if we have no access to the `replayMessages`, a new option `replayAfterDeploy` could also be a solution:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/27a6e640c1c3ae2cf135a988433bddd56d3f21c2.png)

Just an idea ...

---

<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:** [5 October 2019 22:24 UTC](https://discourse.nodered.org/t/refresh-ui-node/13921/26 "2019-10-05T22:24:51Z")

</div>

I smell a PR to dashboard 😂😂😂

---

<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:** [6 October 2019 05:38 UTC](https://discourse.nodered.org/t/refresh-ui-node/13921/27 "2019-10-06T05:38:17Z")

</div>

Morning Steve (@Steve-Mcl),  
a PR for the dashboard? I have no idea what you are talking about 🤣🤣  
Damn, you have published my hidden agenda on the www 🤨  
But perhaps the dashboard master has other/better plans. Only time will tell ...

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [6 October 2019 05:46 UTC](https://discourse.nodered.org/t/refresh-ui-node/13921/28 "2019-10-06T05:46:52Z")

</div>

I think it will be correct if you do it in opposite manner.  
Something like `if(opt.avoidReplayOnDeploy)` then it will be backward compatible and does not affect any existing behavior.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [6 October 2019 08:09 UTC](https://discourse.nodered.org/t/refresh-ui-node/13921/29 "2019-10-06T08:09:44Z")

</div>

Sorry guys, late to this party so probably missing something. This is the state of the input, not an event. So when a second client arrives if it can get put into the current state. If a client is already attached and in that state it can ignore it surely ?

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [6 October 2019 08:51 UTC](https://discourse.nodered.org/t/refresh-ui-node/13921/30 "2019-10-06T08:51:45Z")

</div>

Well for context menu type of widget (which should act mostly on user input) the state sharing hardly can do something useful. Or what?

---

<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:** [6 October 2019 09:21 UTC](https://discourse.nodered.org/t/refresh-ui-node/13921/31 "2019-10-06T09:21:49Z")

</div>

> [@hotNipi](#):
>
> for context menu type of widget

@hotNipi: yes you are right that for our case a second client surely doesn't need to start with the contextmenu of another client. Had never tought about that until now... That makes it even more necessary for us to get this solved. So it is indeed a good remark from Dave! But then a flag named "avoidReplayOnDeploy" doesn't really makes sense anymore...

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [6 October 2019 10:22 UTC](https://discourse.nodered.org/t/refresh-ui-node/13921/32 "2019-10-06T10:22:03Z")

</div>

Don't forget - although I say a second client - this is still not multi-user. There is only one flow running with one overall state. People can do clever tricks using sessions etc to try and separate out different clients but the overall state is still the overall state.

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [6 October 2019 10:47 UTC](https://discourse.nodered.org/t/refresh-ui-node/13921/33 "2019-10-06T10:47:00Z")

</div>

That's the basis of my thinking. For single user, (no matter if equipped with two hands) the multiple context menus to operate at same time is definitely too much (excluding lady's multitasking skills. 🙂 Full respect ). But anyway, I really can't see is there any possible destructive scenario?

---

<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:** [16 October 2019 22:02 UTC](https://discourse.nodered.org/t/refresh-ui-node/13921/34 "2019-10-16T22:02:47Z")

</div>

> [@hotNipi](#):
>
> As you can not ignore first message always (it may be correct message) make your own first message

Evening @hotNipi,  
I'm experimenting with your workaround, but cannot get it working...

So we create a message a frontend, send it to backend, and then we will receive it again at the frontend. But I never receive it again in my message watch...  
Indeed when you look at the handler (for messages coming back from the UI), you see that `storeFrontEndInputAsState` needs to be true (to make sure that the message is stored in `replayMessages` to overwrite the original message):

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/210ff40302a6a2a44f9e8c21db2c539167a06e36.png)

When I set this boolean to `true`, then my own message again arrives in the frontend (so no contextmenu is displayed anymore immediately after a deploy 👍). But as you can see in the above handler (line 279) that own message will also be send on the output of our node. And that is not what we want 👎

P.S. In my test the `scope.unique` is undefined?  
P.S. Think I'm misinterpreting your workaround. While I try to overwrite the original message in the `replayMessages` array, it looks like your are ignore all messages until your arrives. But not sure how to get the same result as you 🥴

---

<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:** [16 October 2019 22:27 UTC](https://discourse.nodered.org/t/refresh-ui-node/13921/35 "2019-10-16T22:27:45Z")

</div>

@BartButenaers, do you know the reason for dashboard to resend messages on deploy? Isn't there a flag to turn this feature off when registering the widget?

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [17 October 2019 04:58 UTC](https://discourse.nodered.org/t/refresh-ui-node/13921/36 "2019-10-17T04:58:04Z")

</div>

`$scope.unique` I used as I tested the workaround with my `ui_level` node and this is unique identifier what you get from `$scope.unique = $scope.$eval('$id')` I think it is not needed in this case at all.

In line 279. If you don't want some message to be passed to next node, set  
msg.\_fromInput = true. You can set it true for your init message and it should then be dropped. But as you can see the comment line - this is kind of hack or temporary solution (many of such last forever), used by native dashboard widget **ui\_dropdown.js** and you'll never know if or when it will be changed or removed. Without any warnings. So this is something I'd not recommend to use as reliable solution. (of course it can be discussed with master)

---

<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 October 2019 06:01 UTC](https://discourse.nodered.org/t/refresh-ui-node/13921/37 "2019-10-17T06:01:21Z")

</div>

> [@Steve-Mcl](#):
>
> @BartButenaers, do you know the reason for dashboard to resend messages on deploy? Isn't there a flag to turn this feature off when registering the widget?

Morning @Steve-Mcl,  
At deploy the replayMessages array contains a message with our node id, so that is replayed. Cannot remove it from the array (since I think I have no access to that array?). And there is no flag that allows me to avoid my message getting stored in the array. So will need to be handled by the dashboard, but Dave responded above that you then impact other clients connecting (which means it becomes harder again to find a good solution to fit for other use cases)...

> [@hotNipi](#):
>
> set  
> msg.\_fromInput = true.

Hey @hotNipi,  
Had considered that also last night (for about 3 seconds 😉). But like you say, the comments are pretty clear that this might change very probably in the (near) future. So I'm afraid I cannot get around it with a simple workaround: the server side stores the message in the replay array, and replays it. Wanted to avoid having to disturb our friend @dceejay, but I'm afraid I cannot workaround this...

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [17 October 2019 06:07 UTC](https://discourse.nodered.org/t/refresh-ui-node/13921/38 "2019-10-17T06:07:50Z")

</div>

> [@BartButenaers](#):
>
> for about 3 seconds

Did you tested it also within that time or it is lucky guess it is working?. Cos I didn't test that all, just reading the code.

---

<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 October 2019 06:55 UTC](https://discourse.nodered.org/t/refresh-ui-node/13921/39 "2019-10-17T06:55:40Z")

</div>

> [@hotNipi](#):
>
> Did you tested it also within that time or it is lucky guess it is working?. Cos I didn't test that all, just reading the code.

Will try that tonight. Thanks for the tip !!

---

<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 October 2019 21:33 UTC](https://discourse.nodered.org/t/refresh-ui-node/13921/40 "2019-10-17T21:33:46Z")

</div>

> [@dceejay](#):
>
> Don't forget - although I say a second client - this is still not multi-user. There is only one flow running with one overall state.

@dceejay,  
Very clever that you have thought about that!!!!!!!!!!

Indeed the last message is stored (in the replayMessages array) and send to any dashboard that needs initial state (e.g. refresh existing dashboard or open new dashboard). So for our Contextmenu-node that is very unwanted behaviour.

Did a quick test: when second dashboard is refreshed, it will get the last contextmenu of the previous dashboard. Here is a demo with **two dashboards** for interested readers:

 ![contextmenu_replay](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/81812b39cbb1a59898b01c6a5e175884ecdb2d01.gif)

> [@hotNipi](#):
>
> Did you tested it also within that time or it is lucky guess it is working?. Cos I didn't test that all, just reading the code.

Your suggestion is indeed very simple to implement, and it seems to work (both for refreshing a dasbhoard and in combination with a second dashboard). Thanks a lot for helping us with this!!!

Here it is, in case anybody ever needs it:

```auto
$scope.init = function (config) {
   // Ignore all input messages that arrive within 1 second after creation of this widget.
   // This way we can avoid the last old message being resend from server to the client...
   $scope.acceptMessages = false;
   setTimeout(function() { 
      $scope.acceptMessages = true; 
   } , 1000);
}

$scope.$watch('msg', function(msg) {
   // Ignore undefined messages.
   if (!msg) {
      return;
   }
                    
   if (!$scope.acceptMessages) {
      return;
   }

   // Process the input message ...

```

Only the time _ **interval of 1 second** _ is a bit of a trial-and-error:

- If I use a _larger_ interval, then I don't get a context menu when I immediately click on a shape.
- If I use a _smaller_ interval, then the old messages might be replayed.

So in my case 1 second works fine. But I could image that this isn't the case in some other setups, e.g. due to a slow internet connection? And adding an extra input field to our config screen (to make the time adjustable by the user) might confuse users, since it is a rather technical issue ...

[Previous page](https://discourse.nodered.org/t/refresh-ui-node/13921.md?page=1)

[Next page](https://discourse.nodered.org/t/refresh-ui-node/13921.md?page=3)
