Skip to content

Commit 15c3594

Browse files
committed
Fix useMemo deps growing between renders in SearchConditions (#94)
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.
1 parent 49f87a0 commit 15c3594

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix React warning in SearchConditions: the useMemo dependency array grew as vocabularies loaded (spread of vocabData values); use the vocabData object itself as a constant-size dependency. @reebalazs

frontend/packages/volto-solr/src/components/theme/SolrSearch/SearchConditions.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,12 @@ export const SearchConditions = ({
147147
})}
148148
</div>
149149
) : null,
150-
// Use spread operator to perform a shallow equality check on the vocabData object
150+
// vocabData comes from useSelector(..., shallowEqual) in useVocabs,
151+
// so its identity only changes when some vocabulary's items change:
152+
// it works as a single dependency. (Spreading its values here made
153+
// the deps array grow as vocabularies loaded, which React warns
154+
// about: the deps array size must stay constant between renders.)
151155
// eslint-disable-next-line react-hooks/exhaustive-deps
152-
[JSON.stringify(facetFields), conditionTree, ...Object.values(vocabData)],
156+
[JSON.stringify(facetFields), conditionTree, vocabData],
153157
);
154158
};

0 commit comments

Comments
 (0)