Skip to content

Conversation

@samouss
Copy link
Contributor

@samouss samouss commented Oct 5, 2018

Summary

The current implementation of addWidgets always trigger a search even without any widgets to add on InstantSearch. We should prevent this behaviour to avoid useless request each time a user call addWidgets without anything.

This issue pops out with a dynamic facetting use case (see example below) - we get an infinite loop because we always call addWidgets without checking the length of the widgets to add. It should be the default behaviour.

// We should not have to do this check inside user code

if (addWidgets.length) {
  search.addWidgets(addWidgets.map(item => item.widget));
}

https://codesandbox.io/s/nnpvp2x8r4

@samouss samouss requested a review from a team October 5, 2018 15:35
@algobot
Copy link
Contributor

algobot commented Oct 5, 2018

Deploy preview for algolia-instantsearch ready!

Built with commit 4091cae

https://deploy-preview-3178--algolia-instantsearch.netlify.com

@francoischalifour francoischalifour merged commit 961626d into develop Oct 5, 2018
@francoischalifour francoischalifour deleted the fix/avoid-useless-search-lifecycle branch October 5, 2018 19:01
tkrugg added a commit to tkrugg/instantsearch.js that referenced this pull request Oct 23, 2018
<a name=2.10.3></a>
## [2.10.3](algolia/instantsearch@v2.10.2...v2.10.3) (2018-10-23)

### Bug Fixes

* **InstantSearch:** avoid useless search on addWidgets ([algolia#3178](algolia#3178)) ([961626d](algolia@961626d))
* **numericselector:** default value can be undefined ([algolia#3139](algolia#3139)) ([39d22f5](algolia@39d22f5))

### Features

* **utils:** add warn function ([algolia#3147](algolia#3147)) ([9de87bb](algolia@9de87bb))
francoischalifour added a commit that referenced this pull request Oct 29, 2018
<a name="2.10.3"></a>

* **deps:** unpin production dependencies ([257ecb7](257ecb7))
* **getRefinements:** provide attributeName for type: query ([6a58b99](6a58b99)), closes [#3205](#3205)
* **InstantSearch:** avoid useless search on addWidgets ([#3178](#3178)) ([961626d](961626d))
* **numericselector:** default value can be undefined ([#3139](#3139)) ([39d22f5](39d22f5))

* **utils:** add warn function ([#3147](#3147)) ([9de87bb](9de87bb))
francoischalifour added a commit that referenced this pull request Oct 29, 2018
<a name="2.10.3"></a>

* **deps:** unpin production dependencies ([257ecb7](257ecb7))
* **getRefinements:** provide attributeName for type: query ([6a58b99](6a58b99)), closes [#3205](#3205)
* **InstantSearch:** avoid useless search on addWidgets ([#3178](#3178)) ([961626d](961626d))
* **numericselector:** default value can be undefined ([#3139](#3139)) ([39d22f5](39d22f5))

* **utils:** add warn function ([#3147](#3147)) ([9de87bb](9de87bb))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants