question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DOCUMENT_ADDED being dispatched multiple times per single add operation

See original GitHub issue

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

  1. Add multiple components that connect to the same collection via firebaseConnect.
  2. Ensure each component is mounted at least once.
  3. Insert a new document into the collection from step 1.
  4. Notice that DOCUMENT_ADDED fires multiple times and the corresponding ordered 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:open
  • Created 5 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
gotdibbscommented, Feb 19, 2019

@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:

<Provider store={store}>
    <BrowserRouter>
        <ReactReduxFirebaseProvider {...rrfProps}>
            // ...
        </ReactReduxFirebaseProvider>
   </BrowserRouter>
</Provider>

…to this:

<Provider store={store}>
    <ReactReduxFirebaseProvider {...rrfProps}>
        <BrowserRouter>
            // ...
        </BrowserRouter>
   </ReactReduxFirebaseProvider>
</Provider>
1reaction
prescottpruecommented, Feb 19, 2019

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

NgRx - Action being dispatched multiple times when in ...
The issue is you didn't unsubscribe from your selects (observables), so they are still live even though component is destroyed.
Read more >
Oracle Manufacturing Cloud 21C What's New
Overview. This guide outlines the information you need to know about new or improved functionality in this update, and describes any tasks you...
Read more >
Statement of Additional Information (SAI) Definition
The SAI is a required document to be formalized by a mutual fund company, but it does not need to be sent to...
Read more >
google/highway: Performance-portable, length-agnostic ...
multiple targets with dynamic dispatch (recommended); single target using -m flags. Projects using Highway: (to add yours, feel free to raise an issue...
Read more >
Get realtime updates with Cloud Firestore - Firebase
An initial call using the callback you provide creates a document snapshot immediately with the current contents of the single document. Then, each...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found