Insert promise not resolving in offline mode. Is this expected?
danmalone89 opened this issue · 2 comments
async saveDocument() {
const id = await this.$store.dispatch('myModule/insert', doc)
// document is added to Vuex store
doSomethingWith(id) // unreachable while offline, despite document being successfully added to Vuex store.
}
Is this the expected behavior when offline? As soon as I go back online, the promise is resolved immediately. Firebase is constantly trying to write to server unsuccessfully while offline, throwing an error every second. I have offline persistence enabled.
@danmalone89
yes this is the expected behaviour.
The library immediately adds the document to the local state, so you don't really need to await
that if that's good enough.
The await
can be used to double check if the record is actually successfully written on the server side, which is therefore delayed when the client is offline.
In your case, you can either, retrieve the id
from a hook like the insertHook, or you can create a random id yourself and pass it as prop to the doc you insert:
const randomId = firebase.firestore().collection('_').doc().id
Let me know if you're stuck!
--
Vuex Easy Firestore was made with ♥ by Luca Ban.
If you use this library in your projects, you can support the maintenance of this library by a small contribution via Github 💜.
You can also reach out on twitter if you want a one-on-one coding review/lesson. 🦜
Thanks @mesqueeb!