Recovering from a paused tab on mobile


#1

I have a problem!

One of our micro apps (Meteor v1.6.1.4 with Blaze v2.3.0) has a startup flow like this:

  1. User opens the site with an identifying URL, such as https://app.com/zKmSa
  2. When the page is loaded, the client calls a method with the id zKmSa and gets some documents in return which are stored in a local collection
  3. Everything works fine and the app uses those documents in the local collection
  4. User switches between browser tabs, does something else for a while on another tab, then re-opens the tab with our app
  5. Oh-oh: All the data in those local client collections is gone, and app state is ruined. In the mobile phone’s browser console I get just Connection timeout. No sockjs heartbeat received.

Any ideas how to solve this problem? How can I persist those documents in the local collections? Maybe I could detect when I’ve lost the local collection content and re-trigger the process for initializing data?


#2

For the time being I solved this by using the PageVisibility API. After a tab becomes visible again, I set up an autorun to detect if we lose the data we already have. Should that happen, the autorun triggers a re-fetch. This causes a small blip in the UI, but seems to work decently otherwise.

I should mention I noticed that for a brief moment after the tab becomes active again, it still holds the data. After a few hundred milliseconds it’s gone however.

I’m storing the documents on client using the Docs._collection reference, maybe that has something to do with it?