Instantsearch.js: Problem with hot addWidget (Cannot read property '_state' of null/helper.lastResults)

Created on 4 Dec 2017  路  3Comments  路  Source: algolia/instantsearch.js

I'm still working out getting a simplified/reproducible case for this. It happens for me on a current app if I merely switch my widget adding to after .start().

Bug: What is the current behavior?
JS error:

InstantSearch.js:297 Uncaught TypeError: Cannot read property '_state' of null
    at InstantSearch.js:297
(anonymous) @ InstantSearch.js:297
setTimeout (async)
(anonymous) @ InstantSearch.js:295
EventEmitter.emit @ events.js:84
AlgoliaSearchHelper._search @ algoliasearch.helper.js:1185
AlgoliaSearchHelper.search @ algoliasearch.helper.js:150
(anonymous) @ InstantSearch.js:278
g @ events.js:165
EventEmitter.emit @ events.js:84
AlgoliaSearchHelper._search @ algoliasearch.helper.js:1185
AlgoliaSearchHelper.search @ algoliasearch.helper.js:150
searchFunction @ index.js:56
helper.search @ InstantSearch.js:280
addWidgets @ InstantSearch.js:162
addWidget @ InstantSearch.js:114
(anonymous) @ index.js:87
addWidgets @ index.js:85
reviewSearch @ index.js:10
each @ jquery.js:370
each @ jquery.js:137
(anonymous) @ index.js:4
__webpack_require__ @ bootstrap 154b3712a560e4cd51c9:19
module.exports.title @ encode.js:85
__webpack_require__ @ bootstrap 154b3712a560e4cd51c9:19
(anonymous) @ vertx (ignored):1
__webpack_require__ @ bootstrap 154b3712a560e4cd51c9:19
(anonymous) @ bootstrap 154b3712a560e4cd51c9:65
(anonymous) @ tail.js:70

What is the version you are using? Always use the latest one before opening a bug issue.
Instantsearch 2.3.1

It appears that helper.lastResults is unexpectedly null .

Core

Most helpful comment

Nope, I removed all my custom widgets and still saw it.

But鈥've distilled this down to a reproducible case! https://jsfiddle.net/timkelty/13jbye0r/
Note: to see this on jsfiddle I had to "preserve log" and hard-refresh several times.

As it doesn't seem to happen every time, I'm thinking it may be some kind of race condition.

Furthermore, It doesn't seem to be related to one widget being before and one after. I tried adding them both after .start and still saw it.

Note: widgets still render and function, just seeing this js error.

All 3 comments

Is it a custom widget?

Nope, I removed all my custom widgets and still saw it.

But鈥've distilled this down to a reproducible case! https://jsfiddle.net/timkelty/13jbye0r/
Note: to see this on jsfiddle I had to "preserve log" and hard-refresh several times.

As it doesn't seem to happen every time, I'm thinking it may be some kind of race condition.

Furthermore, It doesn't seem to be related to one widget being before and one after. I tried adding them both after .start and still saw it.

Note: widgets still render and function, just seeing this js error.

Hi @timkelty thanks a lot for the repro case and the issue,

I have tracked down the issue and this is a really an edge case produced by two new features we added:

  • The hot add/remove widgets API
  • The "search stalled" state (currently used to display a loading indicator for the search box)

What happens:

  1. First request is sent with calling .start()
  2. Second request is sent by adding a new widget
  3. First request too much time, so we re-render widgets with a search is stalled parameter.

But this second render is not correctly done because we don't have access to lastResults since the first request is not done yet.

We are aware of the issue, we want to fix it, I would suggest you to don't add any widgets right after you started the InstantSearch instance.

(You can easily reproduce the issue by simulating a slow network with the code you shared)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

egyprotech picture egyprotech  路  3Comments

anthonyBertrant picture anthonyBertrant  路  3Comments

zackify picture zackify  路  4Comments

ChristopherDosin picture ChristopherDosin  路  4Comments

francoischalifour picture francoischalifour  路  3Comments