instantsearch
instantsearch copied to clipboard
Configure doesn't accept offset + length. Error is thrown
Describe the bug 🐛
Error is thrown if offset
and length
is passed to <Configure />
.
To Reproduce 🔍
https://codesandbox.io/s/elated-dawn-cfb89?file=/src/App.js
Expected behavior 💭
Should display up to the number of items configured in the length
property.
Screenshots 🖥
--
My use case for using offset & length is: in the initial page, I don't want to show pagination and want to restrict to only that fixed number of results, and then if facets are applied, then I'd let the user paginate. This was working normally on 6.4.0, but, after updating to 6.7.0 it is now breaking.
As you can see in the attached screenshot, Algolia does cap the number of hits to the desired number, however, it throws an error when rendering.
One other thing which's definitely related to that is: when I use connectInfiniteHits
and SSR, the initial hits array is [undefined]
. I have to .filter(Boolean)
so my application doesn't crash, but still, the array comes empty if offset and length is passed to <Configure />
.
I wonder if the key length
makes an object "array-like". We had this problem before in facet values, but that was back when we were using lodash.
Is there a reason you're using offset and length, and not regular pagination? If you want to set a default page for infinite hits, that can be done by setting the page value in searchState
.
I don't want to set the default page. I want to cap the number of results for the first page so View more
won't show up unless you apply certain filters (that's the way I have it programmed)
<Configure {...getConfigureProps(hasFilters)} />
function getConfigureProps(hasFilters: boolean) {
const defaultProps = {
maxValuesPerFacet: 20,
hitsPerPage: 3 * 8,
};
if (!hasFilters) {
return {
...defaultProps,
offset: 0,
length: 15,
};
}
return {
...defaultProps,
};
}
Same problems here, I wanted to have different hits for the first page, so I tried to set offset and length dynamically, but wouldn't work
you'll need to transform both the parameters and response to pretend your in offset-only or page-only mode