react-native app crashes without log on Firebase auth logout when using 'onSnapshot' with 'where' query and 'in' operator
The title pretty much says it all. On the home screen, I subscribe to a list of categories using the following code:
e开发者_开发百科xport const subscribeToCategories = ({categoriesList, limit },
callback
) => {
try {
return eventsRef
.where('startDate', '>=', now)
.where('categoryID', 'in', categoriesList)
.orderBy('startDate', 'asc')
.limit(limit)
.onSnapshot(querySnapshot => {
const newStart = querySnapshot?.docs[querySnapshot.docs.length - 1]
const data = []
if (querySnapshot?.size){
querySnapshot?.forEach(doc => {
const event = doc.data()
data.push({ ...event, id: doc.id })
})
}
callback({ eventsData: data, newStart })
})
} catch (err) {
console.log("Could not subscribe: ", err)
}
}
The function is called on the home screen through useEffect
:
useEffect(() => {
if (categoriesList.length === 0 || !limit || !categoriesLoaded) {
return
}
categoriesUnsubscribe.current = eventsAPI.subscribeToCategories( {categoriesList, limit}, onEventsUpdate)
return () => {
categoriesUnsubscribe?.current && categoriesUnsubscribe?.current()
}
}, [categoriesList, limit, categoriesLoaded])
I've confirmed that if I comment out the line of code in the subscribe function with .where('categoryID', 'in', categoriesList)
, the app does not crash upon logout. I've added a condition in the if
statement to make sure the function doesn't run if the list is empty, and a try/catch
block and it still crashes. There are no logs. I'm really stumped.
Help is appreciated. Thanks.
** Edit to add current versions **
"@react-native-async-storage/async-storage": "^1.17.11",
"@react-native-firebase/app": "^16.4.6",
"@react-native-firebase/auth": "^16.4.6",
"@react-native-firebase/firestore": "^16.4.6",
"@react-native-firebase/messaging": "^16.4.6",
"@react-native-firebase/storage": "^16.4.6",
"firebase-admin": "^11.0.1",
"firebase-functions": "^3.23.0",
"react": "18.1.0",
"react-native": "0.70.4",
精彩评论