Fix useMemo deps growing between renders in SearchConditions (#94) - #95
Merged
Merged
Conversation
React warned 'The final argument passed to useMemo changed size between renders': the deps array spread Object.values(vocabData), which grows from 0 to N entries as vocabularies load. vocabData comes from useSelector(..., shallowEqual) in useVocabs, so its identity already changes exactly when some vocabulary's items change - use the object itself as a constant-size dependency.
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 the React dev warning
The final argument passed to useMemo changed size between renderson the search page (#94).The deps array spread
Object.values(vocabData), which grows from 0 to N entries as facet vocabularies load.vocabDatacomes fromuseSelector(..., shallowEqual)inuseVocabs, so its identity already changes exactly when some vocabulary's items change — it serves as a single constant-size dependency with identical recompute triggers (no missed updates, no per-render recomputes; react-redux reuses the previous reference when the equality function passes, in both v7 and v8 semantics).Verified in the browser: warning gone on search page loads with facet vocabularies; all 17 SearchConditions unit tests pass.
Same fix goes to
mainin a separate PR (the bug exists on the release line too).