简体   繁体   English

Firestore似乎无法离线工作

[英]Firestore does not work seem to work offline

I am trying to create a Progressive web app with firestore. 我正在尝试使用Firestore创建渐进式Web应用程序。 The web app works correctly when the computer is online but doesn't work when offline. 当计算机处于联机状态时,Web应用程序可以正常运行,但在脱机状态下则无法运行。

I have enabled firestore offline persistence like below- 我已启用Firestore离线持久性,如下所示:

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 尝试从Firestore数据库获取文档失败,并出现错误

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. 获取离线数据:如果在设备离线时获取文档,Cloud Firestore将从缓存中返回数据。 If the cache does not contain data for that document, or the document does not exist, the get call returns an error. 如果缓存不包含该文档的数据,或者该文档不存在,则get调用将返回错误。

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. 离线持久性并不意味着您的客户可以在没有互联网的情况下与Firestore进行通信,这意味着,例如,一旦再次建立互联网连接,他所做的更改便会提交给相关文档。

Think about caching relevant Files for the User to use the PWA Offline to a certain extend. 考虑为用户缓存相关文件以在一定程度上使用离线PWA。

More info about using it Offline 有关离线使用它的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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