CSFrequency / react-firebase-hooks

React Hooks for Firebase.
Apache License 2.0
3.55k stars 304 forks source link

Firestore useOnce hooks don't fetch unless code change causes hot reload #231

Closed edant92 closed 1 year ago

edant92 commented 2 years ago

I've come across an issue where the useOnce hooks, for example useCollectionOnce() never loads any results - the loading property just returns true and nothing updates.

import { useCollectionDataOnce } from 'react-firebase-hooks/firestore'
...
const userRef = doc(db, "users", userId);
const projectRef = query(collection(userRef, "projects"));
const [values, loading, error, snapshot] = useCollectionDataOnce(projectRef)
...

However, if I change some code and the app hot-reloads - then the results are retrieved. Also, if I use useCollectionData() instead, the results are retrieved as expected.

I'm currently using the follow dependencies:

"firebase": "9.7.0",
"next": "12.1.5",
"react": "18.1.0",
"react-dom": "18.1.0",
"react-firebase-hooks": "5.0.3",

Let me know if I can provide any further details to help debug this.

(also reported by @LouisMazorati here: https://github.com/CSFrequency/react-firebase-hooks/issues/77#issuecomment-1116080951)

(p.s. everything else seems to work smoothly - thanks for a fantastic library!)

marduzca commented 2 years ago

Same thing happening to me at the moment as I was trying to migrate to firebase 9 Except for next (not using it) I'm using all the same dependencies with the same versions

sac-rana commented 2 years ago

Same problem here.

marduzca commented 2 years ago

@chrisbianca Hi Chris. Sorry for tagging you, but I didn't know who else to contact regarding this. I think this is related to new features in React 18. Could this be taken a look at? Probably just migrating the repo to React 18 helps already

pythonicode commented 2 years ago

I'm having this same issue and it's pretty breaking. I'll see if I can figure out a solution.

chrisbianca commented 1 year ago

Hi everybody, apologies for the delay in investigating this properly. I've just given this a try and it appears that some of the changes I've made in the newly released v5.1.0 may have inadvertently resolved this issue.

Could I ask you to try v5.1.0 and check whether this has been fixed?

chrisbianca commented 1 year ago

I am closing this issue as it has been confirmed working in #252, but if anybody else is still struggling, please let me know and I can look into it further!