Fix inverted equality in memoized author/book collection selectors (#43) - #47
Open
sebclark wants to merge 1 commit into
Open
Fix inverted equality in memoized author/book collection selectors (#43)#47sebclark wants to merge 1 commit into
sebclark wants to merge 1 commit into
Conversation
hasDifferentItemsOrOrder returns true when two collections differ, but both client-side collection selectors passed it directly to Reselect as an equality function, where true means 'inputs are equal - reuse the cached result'. Filtering or sorting the author/book index therefore returned the stale unfiltered collection (e.g. Monitored Only left unmonitored authors visible). Negate the comparator so a differing collection invalidates the memoized result. Fixes Chaptarr#43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #43.
@digitalgp's diagnosis is exactly right:
hasDifferentItemsOrOrderreturnstruewhen two collections differ, but both client-side collection selectors pass it to Reselect as an equality function, wheretruemeans "inputs are equal — reuse the cached result". So a filter/sort change that produces a different list is precisely the case that reuses the stale unfiltered result (e.g. Monitored Only leaving unmonitored authors visible).This negates the comparator in both selectors (
createAuthorClientSideCollectionItemsSelector,createBookClientSideCollectionItemsSelector) with a comment explaining the contract so it doesn't regress.Also swept the rest of
frontend/srcfor the pattern: all otherhasDifferentItemsOrOrdercall sites arecomponentDidUpdate-style checks wheretrue → actis the correct sense; these two selectors were the only inversions.