react-firebase-hooks icon indicating copy to clipboard operation
react-firebase-hooks copied to clipboard

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

Open edant92 opened this issue 3 years ago • 4 comments

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!)

edant92 avatar May 03 '22 21:05 edant92

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

marduzca avatar May 04 '22 09:05 marduzca

Same problem here.

sac-rana avatar May 04 '22 14:05 sac-rana

@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

marduzca avatar May 26 '22 11:05 marduzca

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

pythonicode avatar Jul 03 '22 22:07 pythonicode

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 avatar Nov 09 '22 16:11 chrisbianca

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!

chrisbianca avatar Nov 10 '22 16:11 chrisbianca