Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
fix(IndexUtils): avoid throw an error when cleanUp multi index (#1019)
Browse files Browse the repository at this point in the history
  • Loading branch information
samouss committed Mar 1, 2018
1 parent b55b30a commit 865a3c3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/react-instantsearch/src/core/indexUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export function getCurrentRefinementValue(
export function cleanUpValue(searchState, context, id) {
const index = getIndex(context);
const { namespace, attributeName } = getNamespaceAndAttributeName(id);
if (hasMultipleIndex(context)) {
if (hasMultipleIndex(context) && Boolean(searchState.indices)) {
return namespace
? {
...searchState,
Expand Down
14 changes: 14 additions & 0 deletions packages/react-instantsearch/src/core/indexUtils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,20 @@ describe('utility method for manipulating the search state', () => {
},
},
});

// When nothing is refine the searchState doesn't have the indices
// attribute even if we are in a context with <Index>. This should
// not happen, the searchState should always be in sync (indices + no values).
searchState = {
page: 1,
};

searchState = cleanUpValue(searchState, context, 'namespace.refinement');

expect(searchState).toEqual({
page: 1,
namespace: {},
});
});

it('get results', () => {
Expand Down

0 comments on commit 865a3c3

Please sign in to comment.