Having issues with brower navigation back to search page in NextJS

Background:

  • We are using Elasticsearch
  • We are using the search-ui package for react
  • We are using Nextjs

What's happening?

We have a search page that's using the SearchProvider component to wrap all the filters, results, etc. The search results include a link to another page (not another search page, but a more detailed page about the item you clicked). You click the link and you're redirected to the new page, but, when you click the browser navigation to go back to the search page there's no redirect. The url does get updated to the correct search page url which for us is /profiles/search, but you remain on the item detail page.

I've done a lot of debugging and am pretty sure I've narrowed it down to the SearchProvider component. If I remove the usage of SearchProvider entirely the navigation works. I've tried adding a randomly generated key to the provider but that doesn't work. I've tried a dozen other things with console logs to say that the component has remounted but it never does on browser navigation.