Skip to content

Fix query state getting erased on location changes

Administrator requested to merge lg/fix-navbar-query-update into main

Created by: lguychard

Fixes #13805

#13679 moved the logic that updates the navbar query from <GlobalNavbar/>'s constructor (admittedly not a great place to have it) to a useEffect() block, with location as a dependency.

As a result, every time the location was updated, for example when clicking on tokens in a code view, any query state that wasn't persisted to the URL (a partially edited query, or the scoped query added automatically when navigating to a repo/file) would be erased.

The immediate fix I saw was to narrow the dependency array of the useEffect() block, to avoid running it on every location change. But I'm wondering if there isn't still an issue left: the scoped query randomly can get randomly erased on page load (race condition), depending on which of the useEffect() blocks in <GlobalNavbar/> and <RepoContainer/> executes first.

I've simplified the useEffect() block in <GlobalNavbar/> (which could end up calling onNavbarQueryChange() multiple times, had some comments implying that it wouldn't update the query in interactive mode but still did it further down...), fixing the issue as a result, by restricting the cases in which we update the query state.

Merge request reports

Loading