Hide an element based on local session variable

There are certain elements on my page where i have dynamic attribute show if localsession.data.loggedin==true

However even if this variable later turns false by loggig out in another tab, the elements still shows , unless the page is refreshed.

That is it’s show value is bound to a variable but it seems it only checks the variable on load?

what would be the best way to make it see the latest variable ? Schedule a flow every second ? Or some App event ? like mouse focus? Which event will be best ? Or am i doing something wrong and the element should be checking the dynamic attribute on its own even after page load?

Hi @ruast are u developing in asp, php or nodejs?

Hi Max , No server , just a static site

So your site is static but u have dynamic data? how is that?

Through App connect , i call APIs to get my data

yes sorry u can do that, i asked about your server language cause with nodejs u have websockets and the data can be updated in real time.

But with javascript the only way i can think is for example set an action to a button and u can bind the action to load your data, or with a schedule as u said before.

1 Like

I have had to resort to similar tactics when building before I found Wappler; be aware if you have a large mobile user base that a lot of battery-saving daemons or settings in the manufacturer-provided browsers these days are getting obnoxious about killing these types of update cycles after say 30 seconds or 2 mins

We had an internal monitoring website used by about 200 Android and 450 iOS users that had this type of schedule data pull. Over the years that needed about 10 different workarounds to keep the JavaScript from getting put to sleep by Samsung phones, then LG, then even iOS seemed to do it (maybe extensions).

Anyway, nodejs seems to avoid this entirely if it is a fit otherwise.

1 Like

Oh thanks a lot for the heads up. Will change the logic to run the flow as needed. I’m also using the scheduler to run some important flows, will change it

How about the mouse enter event , wonder if that’s a bad idea too? I suppose it won’t work on mobile too

In my experience, events that are triggered by user-initated interactions of any kind are immune from the battery saving stuff - so a button or other interaction based request would seem a bit more reliable to me.

That said, I am new to Wappler and is hard to even be sure if this issue would affect Wappler created sites and apps - but I think it could. Please let us know if you find a good solution.

1 Like

Wonder if this might work Page Visibility API https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API

seems that safari support is partial https://developer.mozilla.org/en-US/docs/Web/API/Document/visibilitychange_event#browser_compatibility