Approach for Initial App Load

Best Practices

I just created a new approach for my initial app load and wanted to share.

My old approach was that, after the user logged in, I would route them to the app's home page and then I would do a bunch of checks on the home page - On Page Load - to make sure their account was configured correctly. I'd check things like whether they were email verified, or whether they'd filled out their first name on their profile (to catch customers that were using a previous version that didn't ask for a first name, etc.). If the customer failed a particular check, I'd branch them off to the page where they could resolve it. It looked quite elegant and I was really proud of how natural and beautiful it looked with those clean branches!

...BUT...

I'd also end up with, what I can only presume were some race conditions. That is, I would end up with cases where the homepage (which in my app is named "MainList") would flash red for a moment (or forever), indicating an unexpected null value was showing up as the page was being constructed. It was intermittent - as race conditions tend to be. And I think it was based on whether or not the values required by the homepage were getting fetched synchronously or asynchronously. And it was turning into a real headache as I started adding more and more functionality to the app! (Keen eyes will also notice that I had a redundant - circular - navigation back to MainList. Yikes!)

Because of the debugging headaches, I determined that maybe it's a bad idea to do a bunch of "page setup" directly on the page that's being constructed. And instead, maybe I should do the setup on another page FIRST and then navigate to the homepage once the the "pre-homepage" has done a bunch of the heavy lifting to make sure everything is ready.

It took me about a day to do this refactoring, but it works GREAT! And I have to say I'm very proud of it!

I call this new "get-everything-set-up-page" my PrimaryPageRouter and it sits in front of most of the places where I navigate to my home page, including being my "Logged In Page" here...

It may turn out to be one of the best things I've built.

Just wanted to share this!

And if folks have thoughts on this approach - or have ideas for even better methods, please share! (especially if you think this method is overkill and that I could have kept doing checks directly on the homepage. would love to hear from you!)

4
5 replies