question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OnSnapshot(useFirestoreDoc) is returning result twice. 1. fromCache: false 2. fromCache: true

See original GitHub issue

Version 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:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jhuleattcommented, Dec 10, 2019

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#L68

0reactions
jamesdanielscommented, Dec 10, 2020

This is the expected behavior of the Firebase JS SDK, which we use. Feature request is #195

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found