-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using updateMany in adapter with custom sortComparer ignores several updates with same id #1853
Comments
I also tried a more simple sortComparer: |
Yeah, I think I see what's happening here. The update logic for processing Here's the logic for "sorted": redux-toolkit/packages/toolkit/src/entities/sorted_state_adapter.ts Lines 75 to 97 in 3b8d7a9
and here's the logic for "unsorted": redux-toolkit/packages/toolkit/src/entities/unsorted_state_adapter.ts Lines 125 to 151 in 3b8d7a9
The unsorted logic continues to merge together the results for each ID. But, for sorted items, the first time we see an update for a given ID we remove the item from I'll be honest and say I don't know why the logic is actually organized like this in the first place :) I copy-pasted the structure from At a minimum, the sorted logic ought to do something similar to what the unsorted logic is doing, or maybe group all updates by ID first. It would be really nice if we could consolidate on a single implementation instead of having this split. I'm afraid this is somewhat lower priority for me atm, but this is a real thing that ought to get fixed. |
@markerikson I'm going to try to address this by merging the sorted/unsorted logic into a single implementation. It doesn't initially appear to make sense to leave them separate. |
Yeah, tbh I don't know why the NgRx folks did it that way to begin with either :) Might want to double-check the early PRs that added the entity adapter code to NgRx in the first place and see if there's hints why they did that? Oh, now that I write that... I'm pretty sure I remember reading either some GH comments or Twitter discussion where the reasoning was to avoid running sorting logic if it wasn't needed, because that can get expensive. searching aha, found it!
and:
also related, this discussion on sorting: ngrx/platform#898 FWIW, I'm totally fine with rearranging / merging the logic in any way that A) keeps the existing tests working, and B) simplifies the implementation. (smaller bundle size would be nice!) |
This should actually be fixed now in #2464 and will be out in whatever the next patch or minor release is. |
When I use updateMany in an adapter with a custom sortComparer, I only see effects of the first update when sending several with the same id. See reproducer here.
The text was updated successfully, but these errors were encountered: