Problem:
When using listenForChanges: true on Firestore APIs, the app progressively slows down and eventually crashes after multiple updates from Firestore.
Symptoms:
- App becomes noticeably slower after 8-9 Firestore updates
- App crashes after 12-15 updates
- Performance degradation is exponential, not linear
Root Cause:
FirestoreAPIProvider stores subscriptions in a List without deduplication. When the same API is called multiple times (via tab switches, navigation callbacks, screen refreshes), new listeners are created each time instead of reusing existing ones.
Each Firestore update then fires ALL accumulated listeners, causing exponential callback execution.
Secondary Issue:
When the page disposes while Firestore listeners are still active, the listener tries to fire on a closed EventBus, causing:
Bad state: Cannot add new events after calling close
Problem:
When using listenForChanges: true on Firestore APIs, the app progressively slows down and eventually crashes after multiple updates from Firestore.
Symptoms:
Root Cause:
FirestoreAPIProvider stores subscriptions in a List without deduplication. When the same API is called multiple times (via tab switches, navigation callbacks, screen refreshes), new listeners are created each time instead of reusing existing ones.
Each Firestore update then fires ALL accumulated listeners, causing exponential callback execution.
Secondary Issue:
When the page disposes while Firestore listeners are still active, the listener tries to fire on a closed EventBus, causing:
Bad state: Cannot add new events after calling close