redux-firestore icon indicating copy to clipboard operation
redux-firestore copied to clipboard

bug(orderedReducer): updating a document on Firestore creates a duplicate on the state

Open Guipsss opened this issue 5 years ago • 4 comments

When updating a document on Firestore, the document is update as intended on the state in real time. But if you change back the property to its initial value, a duplicate is generated on the state. This is happening on the 0.10.0 version.

I'm using it with react-redux-firebase, and had this issue. Rolling back to the previous version (0.9.0) fixed it.

Guipsss avatar Nov 29 '19 19:11 Guipsss

I hit a similar snag on state.firestore.ordered so instead of rolling back to 0.9.0, I used the state.firestore.data property, which wasn't getting the duplicate record added.

Beamanator avatar Dec 01 '19 14:12 Beamanator

Could you share the listener settings that caused this to happen for you or a full repro example? Having trouble replicating the described issue.

As @Beamanator mentioned, it should work to use data state instead, and that is actually a good move since in the future the plan is to have ordered become just keys as described in #204.

prescottprue avatar Dec 04 '19 05:12 prescottprue

I faced with the same issue (in v0.13.0). In my case, I update a doc's field which specified order by to change order, the updated doc has not id key and duplicate the document.

So I tried changing orderedReducer.newArrayWithItemMoved passing arguments to add doc id, it works.

before https://github.com/prescottprue/redux-firestore/blob/b5d5f312a078cb41f3d297863bd67df332a5e265/src/reducers/orderedReducer.js#L63

after

{
  id: action.meta.doc, // Add doc id
  ...action.payload.data
}

I don't know the details, but I thought it might related with this issue. Perhaps, the id key is needed to find on updating so orderReducer duplicates the updated oredered data?

If you still need some example repo, I can create it.

ight-reco avatar May 02 '20 07:05 ight-reco

Experience this same issue. When modifying docs, there is duplication of objects in the ordered array. This duplication does not occur in the data object.

edo avatar Jun 20 '20 21:06 edo