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 to throw an error when we cleanUp an index tha…
Browse files Browse the repository at this point in the history
…t not exist
  • Loading branch information
samouss committed May 23, 2018
1 parent 29fcc22 commit 8770cbd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/react-instantsearch/src/core/indexUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,16 @@ export function cleanUpValue(searchState, context, id) {
const index = getIndex(context);
const { namespace, attributeName } = getNamespaceAndAttributeName(id);
if (hasMultipleIndex(context) && Boolean(searchState.indices)) {
return namespace
const searchStateIndex = searchState.indices[index];
return namespace && searchStateIndex
? {
...searchState,
indices: {
...searchState.indices,
[index]: {
...searchState.indices[index],
...searchStateIndex,
[namespace]: omit(
searchState.indices[index][namespace],
searchStateIndex[namespace],
`${attributeName}`
),
},
Expand Down
23 changes: 23 additions & 0 deletions packages/react-instantsearch/src/core/indexUtils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,29 @@ describe('utility method for manipulating the search state', () => {
page: 1,
namespace: {},
});

// It might happen that we try to cleanUp an index that is not
// present on the searchState. We should not throw an error in
// that case, just return the searchState as it is.
searchState = {
page: 1,
indices: {
second: {
page: 1,
},
},
};

searchState = cleanUpValue(searchState, context, 'menu.category');

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

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

0 comments on commit 8770cbd

Please sign in to comment.