@@ -48,6 +48,7 @@ import type Report from '@src/types/onyx/Report';
4848import type { SubstitutionMap } from './getQueryWithSubstitutions' ;
4949import { getQueryWithSubstitutions } from './getQueryWithSubstitutions' ;
5050import { getUpdatedSubstitutionsMap } from './getUpdatedSubstitutionsMap' ;
51+ import { clearPendingRouterQuery , peekPendingRouterQuery } from './SearchRouterContext' ;
5152import { getContextualReportData , getContextualSearchAutocompleteKey , getContextualSearchQuery } from './SearchRouterUtils' ;
5253import updateAutocompleteSubstitutionsForSelection from './updateAutocompleteSubstitutionsForSelection' ;
5354import useAskConcierge from './useAskConcierge' ;
@@ -77,11 +78,17 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla
7778 const expensifyIcons = useMemoizedLazyExpensifyIcons ( [ 'MagnifyingGlass' , 'ConciergeAvatar' ] ) ;
7879 const { askConcierge, shouldShowAskConcierge} = useAskConcierge ( ) ;
7980
81+ const initialQuery = peekPendingRouterQuery ( ) ;
82+
8083 // The actual input text that the user sees
81- const [ textInputValue , , setTextInputValue ] = useDebouncedState ( '' , 500 ) ;
84+ const [ textInputValue , , setTextInputValue ] = useDebouncedState ( initialQuery , 500 ) ;
8285 // The input text that was last used for autocomplete; needed for the SearchAutocompleteList when browsing list via arrow keys
83- const [ autocompleteQueryValue , setAutocompleteQueryValue ] = useState ( textInputValue ) ;
84- const [ selection , setSelection ] = useState ( { start : textInputValue . length , end : textInputValue . length } ) ;
86+ const [ autocompleteQueryValue , setAutocompleteQueryValue ] = useState ( initialQuery ) ;
87+ const [ selection , setSelection ] = useState ( { start : initialQuery . length , end : initialQuery . length } ) ;
88+
89+ useEffect ( ( ) => {
90+ clearPendingRouterQuery ( ) ;
91+ } , [ ] ) ;
8592 const [ autocompleteSubstitutions , setAutocompleteSubstitutions ] = useState < SubstitutionMap > ( { } ) ;
8693 const textInputRef = useRef < AnimatedTextInputRef > ( null ) ;
8794
0 commit comments