4

Summary

I am using react-native-firebase in my project, and I am running pure react-native (No Expo). However, on putting a get request to any document on Firestore never gives a response. That is, in a try-catch block, neither does it resolve, nor does it get rejected, it keeps on going forever and ever. (And yeah, I know about promises and I am using await/async so its not about waiting for the promise to complete, in fact, the main thing is that promises are not getting resolved/rejected)

The main issue is that this problem comes randomly, its not like it fails every time, it does it randomly. On close observation, I also observed that this happens mostly when I am constantly doing get requests, for example, I have a query which checks for the latest version in a document, now whenever I reload the app, this get query is made, and on 2-3 frequent reloads, this query never resolves.

I can do all other Firebase stuffs, like checking authentication, setting documents data, deleting, modifying editing etc. But this doesn't work out

A Bit of Background Story

This is my first project in react-native and react-native-firebase. In the past, I have been working on Ionic, and native Android (Java). I never faced this issue there. I have been searching on the internet a lot, and a few solutions that I got were mainly for the Firebase Web SDK, and not for react-native-firebase. I found one solution, about resetting user from the Authentication console, but that never worked either. I am putting forward the link which I found (for reference, as my problem is quite similar to this, and mainly differs in the fact that I use react-native-firebase, and not the Firebase Web SDK).

https://github.com/firebase/firebase-js-sdk/issues/533

Code Samples

Get Queries (Few Code Samples which I am using)

let updateData = await firebase.firestore().doc('Updates And Errors/Updates').get();

var expensesDoc = await firebase.firestore().doc(`NewExpenses/${dateToday}`).get()

Expected Output

All Get queries should function at all times.

Actual Output

Get Queries only work when they are not called frequently. (I know its quite weird)

1 Answers1

2

Have you tried using regular promise (then/catch) syntax? I have personally noticed some promise inconsistencies while using the react-native-firebase library with redux-saga's call as well (it simply didn't work, just like you mentioned). To solve my issue, I simply wrapped all the requests in functions that return a new, actual promise, which somehow worked. Still a mystery why though.

Example:

function get (query) {
  return new Promise((resolve, reject) => {
    query.get()
      .then(data => resolve(data))
      .catch(err => reject(err))
  })
}

// Later use:
await get(firebase.firestore().doc('yourDoc'))

If you ever find a proper solution, please let me know, as this code obviously smells.

erikvdplas
  • 551
  • 5
  • 10