Vue-instantsearch: HitsPerPage doesn’t work correctly with routeToState()

Created on 20 May 2019  ·  6Comments  ·  Source: algolia/vue-instantsearch

Bug 🐞

What is the current behavior?

Make a sandbox with the current behavior

Sandbox example: https://codesandbox.io/embed/vueinstantsearchv2starter-8jx9i

What is the expected behavior?

The dropdown should reflect the selected option in the URL when you have selected something other than the default and then reloaded the page.

Does this happen only in specific situations?

What is the proposed solution?

Unsure!

What is the version you are using?

v2.1.0

bug

All 6 comments

Thanks for the bug report.

The issue likely comes from the HitsPerPage component that doesn't pre-select the current refinement, as opposed to the SortBy component.

Aha, so if I were to have a crack at a PR for this would using SortBy as a guide be the simplest way forward?

Yes, it would be!

In addition to not setting the correct value, I've found that the router only updates for changes to the value set at page first load.
E.g. Page loads at /search?hitsPerPage=20, when you select 10 the url changes to /search?hitsPerPage=10, when you select 20 again the url changes to /search.

Setting the initial page loaded value can be achieved by:
<ais-hits-per-page :items="hitsPerPageOptions" />
and

data(){
return {
hitsPerPageOptions: [
        { label: "8 results", value: 8, default: this.$router.currentRoute.query.hitsPerPage != 16 },
        { label: "16 results", value: 16, default: this.$router.currentRoute.query.hitsPerPage == 16 }
      ]
}}

Thanks for writing this workaround @drpeck

Was this page helpful?
0 / 5 - 0 ratings

Related issues

francoischalifour picture francoischalifour  ·  3Comments

timkelty picture timkelty  ·  5Comments

abattenburg picture abattenburg  ·  4Comments

rayrutjes picture rayrutjes  ·  3Comments

socieboy picture socieboy  ·  5Comments