Cloud Firestore collection while offline returns empty

Viewed 26

I am testing the behavior of my React Native app offline. I am using Expo and a Cloud Firestore database. The code that I am using to update the screen is something like:

useEffect(() => {
const unsubscribe = db
  .collection('myCol1')
  .doc('myDoc1)
  .collection('myCol2')
  .onSnapshot((snapshot) => {
    // Update state based on snapshot.docs
    // But snapshot.docs is empty when offline
  });
return unsubscribe; }, []);

While online, everything is working great. Offline however, the collection that is fetched is empty. Is there something obvious that I am missing in terms of how caching works with Cloud Firestore? I am also not sure how to debug that. Thanks!

1 Answers

You can try turning on persistence:

firebase.firestore().enablePersistence();
Related