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

bug(orderedReducer): ordered collection is not updating if using orderBy with desc

Open sintylapse opened this issue 5 years ago • 5 comments

What is the current behavior?

I connect to Firestore like this

firestoreConnect([
    {
        collection: 'emotions',
        orderBy: ['updateDate', 'desc'],
    },
]),

then I open the screen with collection and collections are ordered by updateDate (desc). Then if I update a record

newRecord.updateDate = new Date()

firestore
    .collection('emotions')
    .doc(record.id)
    .update({ ...newRecord })

all content of the record will be updated, but not the order

Screen Shot 2019-09-18 at 15 39 14

If I go back and open screen again, everything is ordered fine again.

Screen Shot 2019-09-18 at 15 46 22

But order works fine if I use orderBy with asc instead of desc

What is the expected behavior? Should update collection order correctly according to it index

Which version of redux-firestore are you using? What about other dependencies? "redux-firestore": "^0.9.0", "react-redux-firebase": "^2.4.1", "react-native": "0.59.10",

sintylapse avatar Sep 20 '19 13:09 sintylapse

This also happens when new documents are added, they’re auto ordered at the end of the query (likely due to lack of order).

zaptrem avatar Sep 26 '19 18:09 zaptrem

I tried to replicate using 0.9.0 and it seemed to be working as expected for me. This test should also cover that case that was reported in #230, so I'm surprised to hear this popped up.

Are you able to provide a Codesandbox or similar where the issue can be replicated?

prescottprue avatar Oct 01 '19 06:10 prescottprue

Looking to make sure this is solved, @sintylapse could you provide a reproduction example using Codesandbox or similar?

prescottprue avatar Dec 04 '19 05:12 prescottprue

Hi, sorry, don't have a time right now. Is it okay if I request reopening this issue if I will be able to reproduce it again and will create reproduction example?

sintylapse avatar Dec 06 '19 13:12 sintylapse

@prescottprue I think I just reproduced this issue in my own app. I've whipped up a sample here: https://codesandbox.io/s/firestore-sort-demo-3izym (relevant code is in components\Sort\Sort.js. Sorry in advance for the ugliness of my quick hack job, but hopefully it gets the point across.

If you click the button a few times to swap data at indices 0 and 1, you'll see how the ordered data gets a bit messy in memory.

I'll try to carve out some time to dig further into this soon myself though, but if you have any thoughts that'd be greatly appreciated.

gotdibbs avatar Mar 14 '20 02:03 gotdibbs