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
π 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.