Instantsearch.js: Avoid to rely on shouldComponentUpdate in component

Created on 8 Aug 2018  路  3Comments  路  Source: algolia/instantsearch.js

Describe the bug 馃悰

The stats widget re-renders only when the nbHits or processingTimeMS changes. It can lead to issue when you are using the page number in the template for example. When you click on the next page with the Pagination widget only the page value changed not the other ones. The shouldComponentUpdate (sCU) function of the widget will return false and so prevent the re-render.

https://github.com/algolia/instantsearch.js/blob/33fa09835df8678085cb7f382b4973eaa1f9b20f/src/components/Stats/Stats.js#L9-L14

To Reproduce 馃攳

  1. Go to https://codesandbox.io/s/l51or5k9lz
  2. Click on the pagination
  3. Stats widget is not updated

Expected behavior 馃挱

We should trigger the re-render. The quick fix is to add more values inside the condition. But do we really need the sCU hook on those components? To have a better idea we can track the effect on the performance with / without the hook.

Bug

All 3 comments

What is SCU @samouss ?

I've update the title and the description.

I'd go for removing the hook, as it is a very straightforward solution. If we find evidence that this particular widget is causing performance issues, we can work on it then.

Was this page helpful?
0 / 5 - 0 ratings