getMaxPage assumes nbPages is always a number
Describe the bug 🐛
getMaxPage assumes nbPages is always a number. This is nolonger true in 4.0.0 as it can be undefined
To Reproduce 🔍
Steps to reproduce the behavior:
- Download an run: https://github.com/algolia/doc-code-samples/tree/master/InstantSearch.js/conditional-request
- In index.html, update instantsearch source script to @4.0.0
- Reload
- See error
Uncaught (in promise) RangeError: Invalid array length

A live example helps a lot! We have a simple online template for you to use for your explanations:
https://codesandbox.io/s/conditional-request-n2cw3
Other widgets assume nbPages is a number:
- InfiniteHits: https://github.com/algolia/instantsearch.js/blob/b454759f513b8681e5c7efd677b0b79da5fac137/src/connectors/infinite-hits/connectInfiniteHits.ts#L189
- Stats: for nbPages and maybe nbHits https://github.com/algolia/instantsearch.js/blob/b454759f513b8681e5c7efd677b0b79da5fac137/src/components/Stats/Stats.js#L29 (people customizing might start getting NaNs)
- Make sure we check for
nbHits,pageandhitsPerPage.
Expected behavior 💭 No errors
Screenshots 🖥 N/A
Environment:
- OS: mac
- Browser: chrome
- Version: 78
Additional context N/A
https://github.com/algolia/instantsearch.js/blob/8feef58c7c8e7b7b1b213d5ed70206304c2c10ed/src/connectors/pagination/connectPagination.ts#L89
this should become
getMaxPage({ nbPages = 0 }) {
or a similar solution then I guess
Actually this is in the contract of the API that nbPages, nbHits, page and hitsPerPage are always returned and a number. Therefore conditional fake responses should have those keys as well, and our documentation includes those keys already.
No further action is needed as this didn't come up for other people.