DOCUMENT_ADDED being dispatched multiple times per single add operation
See original GitHub issueDo you want to request a feature or report a bug?
I believe this to be a bug.
What is the current behavior? When you have multiple components listening to the same collection/key, it appears multiple listeners are added. This ends up producing the side effect of the corresponding ordered collection having new documents be inserted multiple times erroneously.
What is the expected behavior?
When a document is added to a collection, DOCUMENT_ADDED
should only fire once, and the ordered
collection shouldn’t have any duplicates.
Which versions of dependencies, and which browser are affected by this issue? Did this work in previous versions or setups?
redux-firestore@0.6.2
react-redux-firebase@3.0.0-alpha.6
Steps to reproduce and if possible a minimal demo of the problem via codesandbox or similar.
- Add multiple components that connect to the same collection via
firebaseConnect
. - Ensure each component is mounted at least once.
- Insert a new document into the collection from step 1.
- Notice that
DOCUMENT_ADDED
fires multiple times and the correspondingordered
collection now contains duplicates.
Note: my scenario is that of a list view and several derived views (such as dashboards) on separate pages.
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (4 by maintainers)
Top GitHub Comments
@sbtgE I’ve corrected the underlying issue in my fork but I haven’t had time to sort out where the unit test fits in yet.
The workaround is to move the
react-redux-firebase
provider HOC up in the tree. For example, I changed this:…to this:
If it is due to multiple listeners being attached for the same path, folks could try using
oneListenerPerPath
which will only attach one listener, which seems like the intention (since all of those components are connected to the same piece of state, you don’t need multiple listeners).That said, in the future it may be smart to add warnings for this sort of thing since as mentioned, it is really the data that is wanted in all of the components - not multiple listeners attached at the same path. Right?