firebase / firebase/firebase-js-sdk

Firestore: Snapshots not refreshing when iOS app is/was backgrounded

Open
#4,163 4 comments 0 reactions 1 assignee Claimed by @rafikhan View on GitHub
api: firestore feature request
Dominant language
TypeScript
Stars
5.1k
Forks
1k
Avg merge
2d 21h
Merged PRs (30d)
37

Description

### Environment

React Native app (0.63.3) using Firebase 8.1.2 with Firestore 2.0.5. (Javascript API)
Running on Android / iOS, both Simulators and Hardware

### Description

I have a running snapshot on a Firstore collection with chat messages.
This works perfectly on all systems when the app is foregrounded - updates to the observed collection appear almost immediately.

However, I have *very* mixed results when

- quickly backgrounding the app
- sending a message to the app (by adding a document to the observed collection)
- foregrounding the app

This
- seems to work **fine** on my Android test device.
- works **often** on my iOS simulator
- works **rarely** on my test iPhone 6 (iOS 12)

That's as indeterministic as it gets :)

When I then send another message with the foregrounded app, the app gets two updates.

#### Steps to reproduce:

- create a subscription for a collection
- background the app (e.g. by switching to another one)
- update the collection
- reactivate the app
- --> the app does not receive an update in some cases. Easy to reproduce on my iPhone 6 / iOS 12.

- send another message while the app is active
- the app now gets the pending and the new update (2 calls)

#### Relevant Code:

const db = firebase.firestore();
const doc = db.collection("xxx").doc(id);

this.unsubscribe = doc.onSnapshot(docSnapshot => {
// not invoked when the app is backgrounded or coming back to foregrounded
}, err => {
// not invoked when the app is backgrounded or coming back to foregrounded
});

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.