Single Page App: "When Page is Loaded" vs "Do when true"

Pretty much the title. On certain pages, I need things to happen when the page is loaded for the first time.

This is bad though because in the debugger, every time you go to a page within the app, it’s firing off all the “when page is loaded” events. Every. Single. Time. Even if they’re conditional events, it still has to check the condition every time.

Is there a way to do something on my page load just once? Should I use the do when true condition?

I’m skeptical of this because “do when true” makes me feel like it would take up resources just watching and waiting for the condition to come true, especially if I have several “do when true” events watching and waiting.

Again, since my app is a SPA, most of my actions are tied to url parameters.

For example, clicking on a comment icon is a “go to page” workflow, and the floating comment group only displays itself because it’s told to be visible when the url contains comment.

Any tips?

1 Like

Yea I noticed the same, the Page is Loaded event is no bueno for SPAs.

All my “pages” are in reusable groups, so I ended up doing “When condition is true” events in each one and limit them to only when their reusable element is visible + whatever condition I actually wanted in the first place.

Maybe someone has some better advice on this because watching the debugger step-by-step I think it still shows it checking the condition then it not being true, I wish there was a way for it to not even check until visible but :man_shrugging:

3 Likes

Yeah, hopefully we get some more input but I feel much better knowing that I’m not going crazy // the only one seeing this as an issue

SPA’s are special insofar as battery life, device temperature, and app performance are much more finicky on phones. The more complex your SPA, the harder it is to keep everything working well and working well together.

I have a simple workaround for this which uses a boolean state.

Basically it’s a First Page Load state that starts false. I also have all my first load actions in a custom workflow the last action sets the First Page Load state to yes.

On page load i run the First Load custom workflow only when First Page Load is no. States don’t reset unless the page is refreshed

3 Likes

Hey, could you show some Screenshots? Didn’t really get this, sorry… But sounds interesting. I have the same problem here…
Thank you in advance :slight_smile:

So what @ihsanzainal84 is saying, is that he has a custom state boolean value that he flips after the page is first loaded.

And then bases all his decisions on whether to run any further workflows in the same way dependent upon that same boolean.

It’s a neat trick.

Sorry i just saw your post. As mentioned above I have a “yes/no” state that defaults as “no”. I then have a custom event I usually call “First Load Actions”.

In “On page load” , that custom event has a conditional to check that the “yes/no” state is “no”.

On a refresh the custom action runs. It always ends with an action to set that yes/no state to “yes”. So now whenever I use the “go to current page” action the custom event doesn’t trigger.