简体   繁体   中英

Firestore does not work seem to work offline

I am trying to create a Progressive web app with firestore. The web app works correctly when the computer is online but doesn't work when offline.

I have enabled firestore offline persistence like below-

firebase.firestore().settings({ timestampsInSnapshots: true });
firebase.firestore().enablePersistence().then(() => {
    this.db = firebase.firestore();
});

I am getting the following error if I run the app when the computer is offline.

[2018-10-23T07:15:24.406Z]  @firebase/firestore: Firestore (5.5.0): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=unavailable]: The operation could not be completed
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.

Trying to get a document from the firestore database fails with error

Uncaught (in promise) Error: Failed to get document because the client is offline.

I understand that both of these errors are technically correct. But shouldn't these errors not occur because I have enabled offline persistence?

Get offline data: If you get a document while the device is offline, Cloud Firestore returns data from the cache. If the cache does not contain data for that document, or the document does not exist, the get call returns an error.

Query offline data: Querying works with offline persistence. You can retrieve the results of queries with either a direct get or by listening, as described in the preceding sections. You can also create new queries on locally persisted data while the device is offline, but the queries will initially run only against the cached documents.

Offline persistence doesn´t mean that your Client can communicate with Firestore while having no internet, it means that for example Changes he makes get submitted to the relevant Document once a internet connection occurs again.

Think about caching relevant Files for the User to use the PWA Offline to a certain extend.

More info about using it Offline

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM