apollographql / apollo-cache-persist

🎏 Simple persistence for all Apollo Cache implementations
MIT License
1.39k stars 118 forks source link

[question] What's the recommended way to handle render exceptions caused by stale persisted cached data? #501

Open SimpleCreations opened 1 year ago

SimpleCreations commented 1 year ago

Let's say I'm using React + Apollo + apollo-cache-persist with a GraphQL backend. Here's the problem:

  1. Let's say the backend released a broken update, returning data that causes the app to crash
  2. The client caches this data
  3. The client uses the data to render UI
  4. The client crashes
  5. On the next launch, the client tries to use the stale data to render UI
  6. The client crashes
  7. Go back to number 5

In this scenario, the users are stuck with a failing web app/crashing mobile app, and the only solution (once a fix to the backend is pushed) for them is to clear their site data/reinstall the app.

What's the recommended way to solve this? One idea I had so far is to catch render issues with an error boundary and clear the persisted cache in this case.

nrgbistro commented 1 year ago

you could create a version field that is not cached by configuring a CachePersistor. you can then manually manage caching the version in local storage, and if the version updates, clear the cache (or parts of the cache). alternatively, your proposed solution of clearing the cache manually when you encounter an error on the client seems like your best bet.