From 4eb9b36e3d32a7178f18c4a664b8130f49e0ce0e Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Tue, 14 Apr 2026 11:21:20 -0500 Subject: [PATCH] Fix stale searchText in search submit handler The onSubmit handler captured searchText from the render closure, so if the user typed fast and hit enter before React committed the last keystroke's re-render, the search would use a stale value. Use a ref instead so the handler always reads the latest searchText at call time. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/screens/Search/Shell.tsx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/screens/Search/Shell.tsx b/src/screens/Search/Shell.tsx index ac0ad75483..45b6d93786 100644 --- a/src/screens/Search/Shell.tsx +++ b/src/screens/Search/Shell.tsx @@ -97,6 +97,8 @@ export function SearchScreenShell({ // Query terms const [searchText, setSearchText] = useState(queryParam) + const searchTextRef = useRef(searchText) + searchTextRef.current = searchText const {data: autocompleteData, isFetching: isAutocompleteFetching} = useActorAutocompleteQuery(searchText, true) @@ -227,15 +229,12 @@ export function SearchScreenShell({ } }, [setShowAutocomplete, setSearchText, navigation, route.params, route.name]) - const onSubmit = useCallback( - (source: 'typed' | 'autocomplete') => () => { - ax.metric('search:query', { - source, - }) - navigateToItem(searchText) - }, - [ax, navigateToItem, searchText], - ) + const onSubmit = (source: 'typed' | 'autocomplete') => () => { + ax.metric('search:query', { + source, + }) + navigateToItem(searchTextRef.current) + } const onAutocompleteResultPress = useCallback(() => { if (IS_WEB) {