While the device is offline and if you have enabled offline persistence (which in Firestore is enabled by default), your listeners will receive listen events when the locally cached data changes. The first time you attach a listener, Firestore will access the network to download all of the results of your query and provide you a QuerySnapshot
object. If you attach the same listener, the second time and you're using offline persistence, the listener will be fired immediately with the results from the cache. After you get the cached result, Firestore will check with the server to see if there are any changes to your query result. If yes you will get another snapshot with the changes.
Note, if you are using a get()
call, Firestore will still try to hit the network first, to give you as up-to-date data as possible. If you use addSnapshotListener()
instead, Firestore will call you immediately with the cached data, without waiting for the network. That's why you have that ammount of time between the time that you are getting back online and the actual synchronization.
You can also take a look on my answer for this post.