Skip to content

Commit

Permalink
fix(InstantSearch): avoid useless search on addWidgets (#3178)
Browse files Browse the repository at this point in the history
  • Loading branch information
samouss authored and francoischalifour committed Oct 5, 2018
1 parent bae3b45 commit 961626d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/InstantSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ To help you migrate, please refer to the migration guide: https://community.algo
});

// Init the widget directly if instantsearch has been already started
if (this.started) {
if (this.started && Boolean(widgets.length)) {
this.searchParameters = this.widgets.reduce(enhanceConfiguration({}), {
...this.helper.state,
});
Expand Down
14 changes: 14 additions & 0 deletions src/lib/__tests__/InstantSearch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,20 @@ describe('InstantSearch lifecycle', () => {
expect(search.searchParameters.facets).toEqual(['price']);
expect(search.searchParameters.disjunctiveFacets).toEqual(['categories']);
});

it('should not trigger a search without widgets to add', () => {
search.start();

expect(helperSearchSpy.callCount).toBe(1);
expect(search.widgets).toHaveLength(0);
expect(search.started).toBe(true);

search.addWidgets([]);

expect(helperSearchSpy.callCount).toBe(1);
expect(search.widgets).toHaveLength(0);
expect(search.started).toBe(true);
});
});

it('should remove all widgets without triggering a search on dispose', () => {
Expand Down

0 comments on commit 961626d

Please sign in to comment.