Skip to content

Fix inverted equality in memoized author/book collection selectors (#43) - #47

Open
sebclark wants to merge 1 commit into
Chaptarr:developfrom
sebclark:fix-inverted-selector-equality
Open

Fix inverted equality in memoized author/book collection selectors (#43)#47
sebclark wants to merge 1 commit into
Chaptarr:developfrom
sebclark:fix-inverted-selector-equality

Conversation

@sebclark

Copy link
Copy Markdown
Contributor

Fixes #43.

@digitalgp's diagnosis is exactly right: hasDifferentItemsOrOrder returns true when two collections differ, but both client-side collection selectors pass it to Reselect as an equality function, where true means "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/src for the pattern: all other hasDifferentItemsOrOrder call sites are componentDidUpdate-style checks where true → act is the correct sense; these two selectors were the only inversions.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Author and book filters reuse stale memoized collection results

1 participant