I'm developing a PWA and came across this problem on a payment page. Basically:
Scenario 1
The problem is that I have a success page that can't be displayed because when restarting I lose the entire state I was in.
Scenario 2
Is there anything I can do to prevent this? I know that when you open a PWA icon from desktop you're basically opening chrome. But if the app was already opened (and it's still visible in the Recent Tab), is there anything I can do to prevent it from restarting? I guess the phone automatically shuts it down.
Possible solution:
The only one thing I can think of right now is storing everything in localStorage and trying to reload on refresh. This way I can ensure that even if it closes and opens again I remain with the previous state.
Funny thing is that scenario 1 (which bothers me the most) only happens on Samsung Galaxy S7 (tested 6-7 devices until now, and it's the only one it reproduces on). Chrome versions are mostly the same on all of them.
Any ideas? Thanks!
So the save to local storage routine worked. The callback function I was passing to Stripe was getting called, but immediately after the PWA was restarted.
So what I did was to save my state in localStorage the first thing in the callback, with a flag of paymentInProgress
and only then try to call save on server and display the success page. If everything crashed in between, the app got restarted and in componentDidMount
I'm checking for localStorage data and for the paymentInProgress === true
flag.
I'm still curious if there are other solutions to prevent the page reloading from scratch.