Search: Search result page has flickering home page effect
Created by: vovakulikov
Problem
You can see the home page for one or two frames when you're going back from blob or repo pages to the search result page. See the video below
Possible root cause of this
From @vovakulikov
I think I know what happens here. In this place, we track location.search
and set the internal state to the Zustand store searchQueryFromUR
https://sourcegraph.com/-/editor?remote_url=git%40github.com%3Asourcegraph%2Fsourceg[…]sion=v1.2.2&start_row=134&start_col=34&end_row=134&end_col=34
Since useEffect
(and even useLayoutEffect
) have async nature, we're starting to have a false value in SearchPageWrapper because on the blob/repo pages, we didn't have a query in URL query params, and therefore, we set "" to the searchQueryFromURL
. In the next tick/render, we set searchQueryFromURL with parsed query since we have a valid query as URL param on the search result page.
So I'm not sure I have a quick solution here, but it seems that searchQueryFromURL shouldn't exist as a part of the state. This should be a piece of derived information from the URL and its query param.