React-native-firebase: Promise when set data offline

Created on 26 Jun 2017  路  11Comments  路  Source: invertase/react-native-firebase

Hello guys, I have a question.

I have this action on my project:

export function save(data) {
    return (dispatch, getState) => {
        return Firebase.database().ref(`profiles/${data.uid}`).set(data).then(() => {
           dispatch({ type : SAVE_PROFILE });
        });
     }
}

But when I go to offline mode this promise never resolving. How to fix that ?

PS: The data persiste localy, just the promise never resolving


"react": "16.0.0-alpha.12",
"react-native": "0.45.1",
"react-native-firebase": "1.1.1"

I test this using genymotion and real device

Needs Triage Android Database

Most helpful comment

Unfortunately this is out of our control as we rely on the native SDK behaviour. As the iOS documentation states, the set method will only resolve when the data has been committed to the Firebase servers.

https://firebase.google.com/docs/reference/swift/firebasedatabase/api/reference/Classes/DatabaseReference#/c:objc(cs)FIRDatabaseReference(im)setValue:withCompletionBlock:

All 11 comments

Hi, additional information:

When I try to get data, the promise always resolving online or offline. So, probably has a bug on set method of this library.

Hey, is it still actually setting/updating on Firebase?

Yes, pretty sure

@rodolfobarretoweb is this on iOS as well as Android? Do you have persistence enabled?

@chrisbianca Yes, I have the persistence enable, but I not test in ios devices.

@rodolfobarretoweb @chrisbianca my experience with this is that for update and set the callback happens when the data actually syncs with the real database (not the local cached version)

@SamMatthewsIsACommonName Yes, works like you describe but the promise haft to be solved, independent of synchronization or not

Unfortunately this is out of our control as we rely on the native SDK behaviour. As the iOS documentation states, the set method will only resolve when the data has been committed to the Firebase servers.

https://firebase.google.com/docs/reference/swift/firebasedatabase/api/reference/Classes/DatabaseReference#/c:objc(cs)FIRDatabaseReference(im)setValue:withCompletionBlock:

What's the workaround for this? Do we just stop using promises and assume the data was written? Seems a shame.

It seems like the only workaround is to check if offline and resolve the promise, hoping the data got written.

I'm seeing similar problems with adding data to collections, which I presume is due to the same problem. @chrisbianca I know you closed this a while ago, but any thoughts on a workaround on this besides hoping the data gets written? My app needs the id of the new doc after creating it, and as the docs are still being created offline and assigning unique ids, it seems there should be a way to access the them.

UPDATE

Aha! I did a bit more digging and found these two SO posts:

https://stackoverflow.com/questions/49818095/firebase-firestore-when-do-promises-from-offline-write-operations-resolve
https://stackoverflow.com/questions/49829714/firebase-firestore-get-document-id-after-adding-data-offline

For my purposes, the second solution is sufficient.

Was this page helpful?
0 / 5 - 0 ratings