Skip to content

Commit 961626d

Browse files
samoussfrancoischalifour
authored andcommitted
fix(InstantSearch): avoid useless search on addWidgets (#3178)
1 parent bae3b45 commit 961626d

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/lib/InstantSearch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ To help you migrate, please refer to the migration guide: https://community.algo
205205
});
206206

207207
// Init the widget directly if instantsearch has been already started
208-
if (this.started) {
208+
if (this.started && Boolean(widgets.length)) {
209209
this.searchParameters = this.widgets.reduce(enhanceConfiguration({}), {
210210
...this.helper.state,
211211
});

src/lib/__tests__/InstantSearch-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,20 @@ describe('InstantSearch lifecycle', () => {
620620
expect(search.searchParameters.facets).toEqual(['price']);
621621
expect(search.searchParameters.disjunctiveFacets).toEqual(['categories']);
622622
});
623+
624+
it('should not trigger a search without widgets to add', () => {
625+
search.start();
626+
627+
expect(helperSearchSpy.callCount).toBe(1);
628+
expect(search.widgets).toHaveLength(0);
629+
expect(search.started).toBe(true);
630+
631+
search.addWidgets([]);
632+
633+
expect(helperSearchSpy.callCount).toBe(1);
634+
expect(search.widgets).toHaveLength(0);
635+
expect(search.started).toBe(true);
636+
});
623637
});
624638

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

0 commit comments

Comments
 (0)