Skip to content

Firestore: No promise on get() or onSnapshot() when offline (if doc doesn't exist) #1769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mik-rom opened this issue Dec 18, 2018 · 6 comments
Assignees
Labels
help: needs-triage Issue needs additional investigation/triaging. Type: Stale Issue has become stale - automatically added by Stale bot
Milestone

Comments

@mik-rom
Copy link

mik-rom commented Dec 18, 2018

I'll keep it simple as the bug is easy to reproduce.

In firebase docs it says clearly:

If you get a document while the device is offline, Cloud Firestore returns data from the cache. If the cache does not contain data for that document, or the document does not exist, the get call returns an error.
https://firebase.google.com/docs/firestore/manage-data/enable-offline#get_offline_data

// This is what happens when this code is run on a device that is completely offline
const test = async () => {
  try {
    console.log('Before doc')
   // Tried both with and without source option
    let doc = await this.db.collection('listTaskOrder').doc(listId).get({source: 'server'})
    console.log(doc.exists) // <--- NEVER REACHED 
  } catch (error) {
    console.log('catch') // <--- NEVER REACHED 
    console.log(error)
  }
}
test()

This causes an infinite loading screen in my app if the user has no internet connection, because there's no callback whatsoever so the app doesn't know when it's done loading. At least if I get an error I can stop the loading, now i have to figure out some weird workaround. Am I missing something or is this an actual bug?

EDIT: I forgot to mention I got the same behavior with onSnapshot

Using
"react-native-firebase": "^5.1.1",
"react": "16.6.1",
"react-native": "0.57.7",

@mik-rom mik-rom changed the title No callback on get() or onSnapshot() when offline (if doc doesn't exist) Firestore: No callback on get() or onSnapshot() when offline (if doc doesn't exist) Dec 18, 2018
@mik-rom mik-rom changed the title Firestore: No callback on get() or onSnapshot() when offline (if doc doesn't exist) Firestore: No promise on get() or onSnapshot() when offline (if doc doesn't exist) Dec 18, 2018
@mik-rom
Copy link
Author

mik-rom commented Dec 18, 2018

This is strange. After I restart react native I now get the catch from .get(), it returns 'firestore/unavailable'. The problem I had seems to occur only if the app is connected to internet at first and then lose the connection (turn off wifi) and then do a simple reload. In that case I get no promise at all. It's only after I restart the app I again I get an error as expected.

@Salakar Salakar self-assigned this Dec 19, 2018
@Salakar Salakar added the help: needs-triage Issue needs additional investigation/triaging. label Dec 19, 2018
@Salakar Salakar added this to the v6.0.0 milestone Dec 19, 2018
@stale
Copy link

stale bot commented Jan 16, 2019

Hello 👋, this issue has been automatically marked as stale because it has not had activity for quite some time. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Type: Stale Issue has become stale - automatically added by Stale bot label Jan 16, 2019
@stale
Copy link

stale bot commented Jan 30, 2019

Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Jan 30, 2019
@Graig123git
Copy link

I am currently having this issue, i am using react native Expo client to run my app please note
my app is not live. how can i test these fail cases while using the expo client to run my app?

@aureliopetrone
Copy link

There is an error with the request maybe. Try to do this:

    let doc = await this.db.collection('listTaskOrder').doc(listId).get({source: 'server'}, (error)=>console.log("ERROR", error))

@bennbollay
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help: needs-triage Issue needs additional investigation/triaging. Type: Stale Issue has become stale - automatically added by Stale bot
Projects
None yet
Development

No branches or pull requests

5 participants