Custom Nanoflow Not Triggering on First Load of Native Mobile Page

0
Hi all,   I am working on a native mobile app in Mendix & I have created a custom nanoflow that should run automatically when a page loads. It fetches user specific data & sets a few UI states. The strange issue is; the nanoflow doesn’t trigger the first time the page loads after launching the app. If I navigate away and return to the page; it works as expected from that point onward.   I have checked for errors in the console and logs, but nothing is thrown. The nanoflow is definitely linked to the "On Page Load" event. I suspect it could be a context object not being available yet / possibly a race condition due to local storage sync / entity permissions on the first load. I am not using any complex logic just a retrieve & a couple of UI changes. Checked https://docs.mendix.com/refguide/nanoflows/ with CCSP Training guide for reference.    Has anyone else experienced this inconsistency on native apps? Is there a best practice to ensure nanoflows fire reliably on the very first render of a native page? Any help or workaround is appreciated!       Thank you !!       Thank you !!
asked
1 answers
0

This can happen on the home page, especially if you create your context object with a DS nanoflow. The AppEvents widget is a little eager and will call your onload event even if the context is not loaded yet into the dataview.

 

I use an enum for that, with values created and initialized and add an attribute on the context object with that enum. The DS nanoflow or native navigation nanoflow creates the object with enum value created. On the page, show AppEvents widget only if the enum is anything but empty. In the AppEvents onload nanoflow I set the state to initialized. I use this pattern all the time, to do initialization before actually showing the home page content. You can wrap the other content in a container with condition for visible set to the initialized value.

 

This way, the AppEvents widget will call your nanoflow with a valid context object and you can show other content after your initialization has finished, like getting local storage content or triggering a synchronization

answered