Search code examples
angulargoogle-cloud-firestoreangularfire2angularfire

AngularFire doesn't detect changes if persistence is enabled


I'm using AngularFire and have the persistence for offline support enabled in my app.module.ts:

imports: [
   AngularFireModule.initializeApp(environment.firebase),
   AngularFirestoreModule.enablePersistence()
]

When my application start, I retrieve the user using valueChanges() like the following:

const doc: AngularFirestoreDocument<User> = this.myCollection.doc<User>(userId);

doc.valueChanges().pipe(take(1)).subscribe((user: User) => {
    console.log(user);
}, (err) => {
    console.err(err);
});

Strangely to me, if I applies modifications to the database from another source as the application, for example if I log my self into the Google Firestore Console and modify manually a value in the user data, these data won't be fetched.

If I restart the app it will always fetch the locally persisted data and will never notice that the values were changed.

If I remove the persistence, respectively the enablePersistence(), the data are correctly fetched.

Do you know what's the reason of the problem?

Should I not use the valueChanges() in such case?

Or does this happens because I fetch the value only once (see take(1)) and therefore the updated value is never fetched?

Thx in advance for the help


Solution

  • 5 minutes later...exactly my problem is the fact that I'm not listening for changes and only reading one value (take(1)), respectively the locally persisted one will be read and nothing more afterwards, therefore the updated value won't be fetched