You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.
This is pretty hard to reproduce. Sometimes it works and sometimes it doesn't. What I find to be consistent is testing this right after the component loads.
I've done some digging and this happens only when this.values.min or this.values.max of RangeInput is set to null. This is the case when the component is first loaded but it can happen in other cases. The possible cases for those two values are in the following code
The solution is really a question of architecture. There are two libs at play here (instantsearch.js and vue-instantsearch) and either of them could be changed to fix this.
When either nextMin or nextMax is set to undefined or '', the code thinks that the user is trying to reset either the upper or lower bound of the range. This is the right behavior and works as expected.
When either is set to null the code does not think that the user is trying to reset part of the filter. Instead, it tries to set the value to null. Because the code supports strings as arguments, it ends up trying to parse null as a number which leads to NaN. That NaN value ends up failing one of the validity checks in the code and the refine function does nothing.
One solution to this is to change the refine function in instantsearch.js's connectRange so that it considers null as a possible empty value treating it like undefined or ''.
Fixing vue-instantsearch
vue-instantsearch does not respect the contract established by connectRange. From what I've described above, connectRange does not handle null. It only handles undefined and '' as empty values.
The fix would be to change this.values in RangeInput to fallback on undefined if it can't find a proper value for either min or max. The code in question is here:
Bug 🐞
What is the current behavior?
Here are the steps to reproduce:
Note that the results are not updated.
Make a sandbox with the current behavior
I have managed to reproduce this on the sandbox from the documentation here: https://vue-instantsearch.netlify.app/stories/?selectedKind=ais-range-input&selectedStory=default&full=0&addons=1&stories=1&panelRight=1&addonPanel=storybooks%2Fstorybook-addon-knobs
What is the expected behavior?
The results should get updated
Does this happen only in specific situations?
This is pretty hard to reproduce. Sometimes it works and sometimes it doesn't. What I find to be consistent is testing this right after the component loads.
I've done some digging and this happens only when
this.values.min
orthis.values.max
ofRangeInput
is set tonull
. This is the case when the component is first loaded but it can happen in other cases. The possible cases for those two values are in the following codevue-instantsearch/src/components/RangeInput.vue
Lines 120 to 128 in 9bb117c
What is the proposed solution?
The solution is really a question of architecture. There are two libs at play here (
instantsearch.js
andvue-instantsearch
) and either of them could be changed to fix this.Fixing
instantsearch.js
instantsearch.js
does not fully handle the "empty" values inconnectRange
. Specifically, it handlesundefined
and''
but notnull
. This can be seen here: https://github.com/algolia/instantsearch.js/blob/5209bdb9189e7cbbf9514b62fde55f923b2b3273/src/connectors/range/connectRange.js#L123-L127When either
nextMin
ornextMax
is set toundefined
or''
, the code thinks that the user is trying to reset either the upper or lower bound of the range. This is the right behavior and works as expected.When either is set to
null
the code does not think that the user is trying to reset part of the filter. Instead, it tries to set the value tonull
. Because the code supports strings as arguments, it ends up trying to parsenull
as a number which leads toNaN
. ThatNaN
value ends up failing one of the validity checks in the code and the refine function does nothing.One solution to this is to change the
refine
function ininstantsearch.js
'sconnectRange
so that it considersnull
as a possible empty value treating it likeundefined
or''
.Fixing
vue-instantsearch
vue-instantsearch
does not respect the contract established byconnectRange
. From what I've described above,connectRange
does not handlenull
. It only handlesundefined
and''
as empty values.The fix would be to change
this.values
inRangeInput
to fallback onundefined
if it can't find a proper value for eithermin
ormax
. The code in question is here:vue-instantsearch/src/components/RangeInput.vue
Lines 120 to 128 in 9bb117c
The fix would be to replace those
null
s withundefined
s.What is the version you are using?
I'm running
vue-instantsearch@v3.1.0
. The full list of algolia packages that I'm using with their matching version are:The text was updated successfully, but these errors were encountered: