Search state changes on route change help

I am using React Instantsearch with React Router v5.2. I am currently working on keeping the searchState in the URL. I have used the functions from the Routing URLs docs to get me started. I have a custom search box on my home page. When a user searches for an item, I am using history.push to send them to my search page. The URL updates and pushes correctly when you are first sent to the search page, but quickly gets reset to a blank search. What could be causing this issue?

Here is a code sandbox that demonstrates the problem.
onSearchStateChange Issues

I think the issue is in the onSearchStateChange function that I am using from the docs.

const onSearchStateChange = (updatedSearchState) => {

      setTimeout(() => {
        history.push(searchStateToUrl(history, updatedSearchState), updatedSearchState);


It seems to call the function several times on route change which overwrites the query that is there. I’m not sure how to modify the function to prevent this.