Skip to content

Fix: race condition for undefined patternTypes in interactive mode

Administrator requested to merge fa/pattern-type-race into master

Created by: attfarhan

While looking into https://github.com/sourcegraph/sourcegraph/issues/8161, I noticed a race condition that causes a bug.

The bug:

The relevant code is in https://sourcegraph.com/github.com/sourcegraph/sourcegraph@b887ad1/-/blob/web/src/search/results/SearchResults.tsx#L96-108. What happens is that the SearchResults page renders, notices there is no patternType, and redirects you to the URL with a patternType. However, this.props.navbarSearchQueryState.query is not defined yet, because it gets set by InteractiveModeInput in https://sourcegraph.com/github.com/sourcegraph/sourcegraph@fa/pattern-type-race/-/blob/web/src/search/input/interactive/InteractiveModeInput.tsx#L68:34. But, since interactive mode is behind the splitSearchModes feature flag, we need to query the global settings before we render interactiveModeInput, so we fail to update the query before the redirect occurs.

The safe thing to do is to always parse the intended query out of the URL when doing a redirect.

Merge request reports

Loading