databasefirebasegoogle-cloud-platformgoogle-cloud-firestoreoffline

Firebase Firestore: Accessing Never-Retrieved Data Offline


I'm using Firebase Firestore v.10 in my web app and want to improve offline functionality. While I understand Firestore allows accessing cached documents offline, is it possible to fetch data (never retrieved before) when the device is offline?

I have a list of users that I can access offline. However, when I click on a specific user to view their details, it doesn't show any information unless I've previously accessed that user online

What I'm trying to achieve:

Allow users to access specific data points even when offline, even if they haven't interacted with that data before.


Solution

  • I have a list of users that I can access offline.

    If this list already exists in memory, on the local storage, or you already read it from Firestore and exist in the cache, then such a list will always be accessible while offline.

    However, when I click on a specific user to view their details, it doesn't show any information unless I've previously accessed that user online.

    This is happening because most likely, to get the user details you have to perform a new Firestore request, and since the device is offline, you have to wait until you regain connectivity. Please also note, that you can access user information that was previously accessed because Firestore creates its own cached version of the database. So as soon as you read something, the data is written in the cache so it can be accessible when the device becomes offline.

    If you want to have the list of users together with all user details, then you have to add all user details to the initial list. Or, you can create a query, while the device is online, to get all user details in advance so it can be available when the device loses connectivity.