algolia / instantsearch

⚑️ Libraries for building performant and instant search and recommend experiences with Algolia. Compatible with JavaScript, TypeScript, React and Vue.

Home Page:https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Next.js - createURL function called outside of instant search context

FaroukMekk opened this issue Β· comments

πŸ› Current behavior

I use the createURL options to personalize the URL of my search page with the new next.js router.

However, I see that this function is called even after I quit the search page and it generates troubles with the routing of the others pages.

πŸ” Steps to reproduce

  • Click on a item in the list
  • get to the details page
  • see that the createURL function has been called

Live reproduction

https://codesandbox.io/p/sandbox/exciting-wright-yxmy7k?file=%2Fpages%2Findex.js&selection=%5B%7B%22endColumn%22%3A15%2C%22endLineNumber%22%3A35%2C%22startColumn%22%3A15%2C%22startLineNumber%22%3A35%7D%5D

πŸ’­ Expected behavior

createURl shouldn't be called outside of instant search context

Package version

react-instantsearch-hooks 6.40.1

Operating system

No response

Browser

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Hi @FaroukMekk, thanks for using InstantSearch and raising this issue !

Indeed, history router does call write when it gets disposed of :

While it makes sense to do so when calling dispose while still on the search page, this probably should not be the case when going onto a different page.

We'll fix that if not too impactful and will get back to you once it's done :)

I believe the solution would be #4162

Do you think that there is an easy workaround while waiting for a possible fix ?

The easiest workaround is taking the code of the history router, adopting it in your app, and removing the this.write in the dispose function, or using patch-package to remove it.

Otherwise if you have a good idea what an option should be called for disabling cleanup / write on unmount / dispose, we'd happily think about this further, as there's some edge cases where it would help to disable the cleanup.