search: prevent the rendering of the home page when navigating back to the search results
Created by: valerybugakov
Context
TLDR
We render the search home page when navigating back to search results from the blob view. Don't believe me?
Go to the cloud instance, set a breakpoint in the SearchPage.tsx
file in dev tools and try yourself!
Details
Currently, we have parsedSearchQuery
in the state of the SourcegraphWebApp
component.
- Upon opening search results — its value is updated with the current search query.
- After opening any search result — its value is set to an empty string.
- When we navigate back to search results we there's a delay in updating its value because:
- The update is done in the
useEffect
hook in theLayout
component, which is rendered after we figure out which React router route to use. https://github.com/sourcegraph/sourcegraph/blob/ee1e1fe5af79de620292c6794dcbff2c6a47fe71/client/web/src/Layout.tsx#L155-L158 - It means that the code responsible for deciding what to render doesn't have up-to-date
parsedSearchQuery
available on the initial render. It leads to rendering theSearchPage
component, which we don't need, negatively affecting the perceived performance. https://github.com/sourcegraph/sourcegraph/blob/ee1e1fe5af79de620292c6794dcbff2c6a47fe71/client/web/src/routes.tsx#L78-L82
- The update is done in the
Changes
- This PR removes
parsedSearchQuery
from the state of theSourcegraphWebApp
component.- It seems it's required only in the
SourcegraphWebApp
componentDidMount
hook, and deleting it from the state doesn't break things.
- It seems it's required only in the
- Uses
parsedSearchQuery
directly from theLayout
component that we already have in place.
As a result — the StreamingSearchResults
component is rendered right away when navigating back to search results without redundant intermediate steps.
Preparation to address https://github.com/sourcegraph/sourcegraph/issues/28845.