keithamoss / mapa

2 stars 0 forks source link

Plan for development of offline support #821

Open keithamoss opened 7 months ago

keithamoss commented 7 months ago

The user believes built-in offline support would be useful. e.g. When truly offline or just when on an unreliable / low bar count connection like in the hills around Kalamunda et cetera.

Relevant links

At the time of writing the two main libraries that used to provide offline support with Redux appear to be entirely abandoned and nothing is rising up to take their place.

There's a GitHub issue (xx) where various people, and the authors of Redux Toolkit and RTK Query, discuss offline support. Again, at the time of writing, no decision is taken to add support into the library, integrate with third party libraries (there are none, per above), nor offer any doco or patterns showing how to implement offline support alongside Redux Toolkit and RTK Query.

The second link above (the Innoq blog post) appears to be our best bet. It's a well thought out argument in favour of its approach and it's a generic pattern we could - seemingly - apply within our architecture.

It's silent on use of local storage (I think?), but that's the logical choice.

Questions for the user to inform the POC and design:

  1. Discuss a discrete offline/online toggle vs automatic detection. Should the app be always ready to go offline (arguably yes, and is a more seamless integration) or should it require the user to take an action (like saving lists or creating an offline export of a map). Goes to a question of user behaviour.
  2. What is iOS Safari like with localStorage, how much can it hold, for how long, and how reliable is it? Does it play reliably with apps pinned to the home screen?
  3. API calls aside, what other web resources/assets do we rely on that we would need to have a local version of to truly enable fully offline functionality (e.g. launching the pinned app fresh from the gold screen on no connection). If so, what's the best way to cache them locally and are there any libraries that'll just do that for us?

Next steps:

  1. Discuss with the user per above
  2. POC the approach and ensure we can use the Innoq proposal with RTK Query.

Other considerations:

Lots of food for thought!

keithamoss commented 6 months ago

This would also be useful for when the connection is poor. Which maybe we could detect too?

Ideally we'd be able to background sync automatically once the user is on a good connection. Not sure if that's possible with a PWA on iOS? Maybe that's where Service Workers come in though?

keithamoss commented 5 months ago

https://vite-pwa-org.netlify.app/

keithamoss commented 2 months ago

Service Workers look like the go for easier offline caching of all of the assets we need. i.e. They're good at intercepting network requests and returned a cached verison.