Firebase Firestore:离线写入操作的承诺何时解决?

the*_*ace 7 javascript offline firebase google-cloud-firestore

我按照文档中所述离线激活:

firebase
    .firestore()
    .enablePersistence()
    .then(() => {
      console.log('offlinemode acctivated')
    })
Run Code Online (Sandbox Code Playgroud)

日志显示如我所料。

添加数据时,如下所示:

db
    .collection('foo')
    .add({foo: 'bar'})
    .then(docRef => {
      console.log('Added Foo: ', docRef.id)
      // do some stuff here with the newly created foo and it's id.
    })
    .catch(console.error)
Run Code Online (Sandbox Code Playgroud)

.then()离线时也不会.catch()被呼叫。即使在执行此回调时该对象已添加到我的离线数据库中的 foo 集合中也是如此:

db
    .collection('foo')
    .onSnapshot(callback)
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?我预计这个承诺要么失败,要么解决,这样我就可以做出相应的反应。

Dou*_*son 5

仅当服务器确认写入已完成时,Firestore 中写入操作的承诺才会解析,即使它们可能已成功写入本地缓存。