diff --git a/packages/react-instantsearch/src/core/createInstantSearchManager.derived.test.js b/packages/react-instantsearch/src/core/createInstantSearchManager.derived.test.js index 2dac87a1f1..9d3d3d3ac7 100644 --- a/packages/react-instantsearch/src/core/createInstantSearchManager.derived.test.js +++ b/packages/react-instantsearch/src/core/createInstantSearchManager.derived.test.js @@ -120,7 +120,82 @@ describe('createInstantSearchManager', () => { }); }); }); + + it('updates the store and searches with duplicate Index & SortBy', () => { + // + // + // + // + // + // + // + // + // ; + + const ism = createInstantSearchManager({ + indexName: 'first', + initialState: {}, + searchParameters: {}, + algoliaClient: client, + }); + + // + ism.widgetsManager.registerWidget({ + getSearchParameters: params => params.setQuery('query'), + context: {}, + props: {}, + }); + + // + ism.widgetsManager.registerWidget({ + getSearchParameters: x => x.setIndex('first'), + context: {}, + props: { + indexName: 'first', + }, + }); + + // + // + // + ism.widgetsManager.registerWidget({ + getSearchParameters: x => x.setIndex('third'), + context: { multiIndexContext: { targetedIndex: 'first' } }, + props: {}, + }); + + // + ism.widgetsManager.registerWidget({ + getSearchParameters: x => x.setIndex('second'), + context: {}, + props: { + indexName: 'second', + }, + }); + + expect(ism.store.getState().results).toBe(null); + + ism.widgetsManager.update(); + + return Promise.resolve().then(() => { + jest.runAllTimers(); + + expect(ism.store.getState().results).toEqual({ + first: { + index: 'third', + query: 'query', + page: 0, + }, + second: { + index: 'second', + query: 'query', + page: 0, + }, + }); + }); + }); }); + describe('on external updates', () => { it('updates the store and searches', () => { const ism = createInstantSearchManager({ diff --git a/packages/react-instantsearch/src/core/createInstantSearchManager.js b/packages/react-instantsearch/src/core/createInstantSearchManager.js index 5b8789d3b6..f4c64bd1ec 100644 --- a/packages/react-instantsearch/src/core/createInstantSearchManager.js +++ b/packages/react-instantsearch/src/core/createInstantSearchManager.js @@ -121,6 +121,8 @@ export default function createInstantSearchManager({ sharedParameters ); + indexMapping[mainIndexParameters.index] = indexName; + return { sharedParameters, mainIndexParameters, derivatedWidgets }; } diff --git a/stories/MultiIndex.stories.js b/stories/MultiIndex.stories.js index 0687b2f8bb..6a7931d6f3 100644 --- a/stories/MultiIndex.stories.js +++ b/stories/MultiIndex.stories.js @@ -7,6 +7,7 @@ import { Index, Highlight, SearchBox, + SortBy, } from '../packages/react-instantsearch/dom'; import { connectHits, @@ -62,6 +63,47 @@ stories )) + .add('with SortBy nested in same Index as Root', () => ( + + + + + + + + + + + + + + + + + + + + + + + + )) .add('with conditional rendering', () => (