By default (at least if you are using Expo) it seems that if you try to .get()
something from Firestore with no internet connection, the data will be returned from cache, even if the local persistence is not implemented in the browser.
You can see this behavior on Expo, with the original firebase sdk, if you run this method without connection:
async function performSomeQuery(query, limit) {
const querySnapshot = await query.limit(limit).get();
if (querySnapshot.metadata.fromCache) {
throw new Error("It is from cache!");
}
if (querySnapshot.empty) {
return [];
}
const result = querySnapshot.docs.map(parseDoc);
return result;
}
For me, this behavior is a little confusing… because if you try to enable the Firestore local persistence in your Expo app, you will get the error code: unimplemented
firebase.firestore().enablePersistence()
.catch((err) => {
console.log(err.code); // unimplemented for Expo
});
How can I receive exceptions instead of “cached” data when the internet is not connected??