Error when limiting items with Firestore

Viewed 265

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...

1 Answers

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

Related