9

When I use Firestore, and I do the following:

  • I query a list of items with a limit.
  • I delete an item from that list, then I delete another one.
  • The rest of the items start to disappear (they are not deleted, they are just not shown to the user that is logged in).
  • If I clear cache/cookies or use incognito window, the items disappeared are shown again, but if I delete another item again, they start to disappear for this user too.

I have created a Stackblitz reproducing the error: https://stackblitz.com/edit/angular-yhbuma

To reproduce the app you only have to fill the Firebase config in app.module.ts:

enter image description here

Just start to add items clicking on ADD ITEM, until you have enough to have more than 1 "page". Then click on DELETE, in one, then in another one...

Diego
  • 709
  • 7
  • 18
  • I gave a quick look to your project. Take a look at ngrx-effects and, in any case, call services from there, then, save everything you get on the store and on the reducer return watch you need by filtering. You can also perform CRUD operations using entities. – AndreaM16 Nov 19 '17 at 17:24
  • I used to use effects, but they were giving me errors when using Angular Universal, so I avoided them. I just migrated from a Firebase Realtime Database to Firestore, and with Realtime Database I was not having problems with this code. – Diego Nov 19 '17 at 17:30
  • Try refer pageLimit from cache(LocalStorage) instead of variable (edit the firebase config) - https://stackblitz.com/edit/angular-hugmk8 – Sivaraj S Nov 29 '17 at 02:39

1 Answers1

0

In item.service function getItems is returning an Observable, so when you call getItems() in home component you don't unsubscribe the previous subscription. This leads to situation when you have this method called 3 times, you watch 3 times for this which can leads to your error. Try to add some subscription handler and unsubscribe previous when you call next https://stackblitz.com/edit/angular-ldvhff

Wojciech Parys
  • 339
  • 2
  • 18