OnSnapshot(useFirestoreDoc) is returning result twice. 1. fromCache: false 2. fromCache: true
See original GitHub issueVersion info
React: 16.9.0
Firebase: 7.2.0
ReactFire: 2.0.0-canary.1fce6b9
Other (e.g. Node, browser, operating system) (if applicable):
Issue
When I use useFirestoreDoc, it has useState hook somewhere inside (I am guessing somewhere inside useObservable) and useFirestoreDoc is using onSnapshot method of firebase and returns snapshot result of queried document.
When I tried to log this snapshot, I am getting the result twice:
1. _fromCache: false
2. _fromCache: true
This renders the component 2 times, because useState hook is used inside useObservable.
My Questions
-
Why it is sending 2 results??
-
How can I rectify this 2 renders issue?
-
_fromCache: true
is only expected when user is offline, why it is fetching from cache even when user is online??
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
onSnapshot fromCache always false when change is local
The firebase client receives the return message and does nothing (does not trigger a onSnapshot ) because the server data agrees with the...
Read more >Separate Firestore onSnapshot listeners interfering with each ...
I have two separate Firestore onSnapshot callback functions, one is on a CollectionReference, ... The meta info for this result shows the fromCache...
Read more >Access data offline | Firestore - Firebase
If fromCache is true , the data came from the cache and might be stale or incomplete. If fromCache is false , the...
Read more >firebase query firestore collection not working react native
Looks like what I needed to do was use the _document.data property on each snapshot returned by the forEach on the querySnapshot. So...
Read more >51. Glitch FIX: Solving Firebase Firestore onSnapshot ...
It turns out Firestore has a local cache that is shared between all queries that can first be returned with a metadata cache...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I haven’t had much time to look at this. Hopefully will have more this week. My assumption that this is caused by
useObservable
piping an initial value into the Observable: https://github.com/FirebaseExtended/reactfire/blob/e1daab435f10c629267ff8c2966da878327c941d/reactfire/useObservable/index.ts#L68This is the expected behavior of the Firebase JS SDK, which we use. Feature request is #195