From 614df8409ff9982d4774de13cedaef29ce976851 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Tue, 14 Apr 2026 11:28:32 -0500 Subject: [PATCH] Update searchText ref eagerly at setState time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Setting the ref during render doesn't fix the race — if React hasn't re-rendered yet, the ref is just as stale as the closure. Write to the ref at the same time as the setState call so it's current before React schedules the re-render. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/screens/Search/Shell.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/screens/Search/Shell.tsx b/src/screens/Search/Shell.tsx index 45b6d93786..9f6dc67d27 100644 --- a/src/screens/Search/Shell.tsx +++ b/src/screens/Search/Shell.tsx @@ -96,9 +96,12 @@ export function SearchScreenShell({ const [activeTab, setActiveTab] = useState(() => getTabIndex(tabParam)) // Query terms - const [searchText, setSearchText] = useState(queryParam) + const [searchText, _setSearchText] = useState(queryParam) const searchTextRef = useRef(searchText) - searchTextRef.current = searchText + const setSearchText = (text: string) => { + searchTextRef.current = text + _setSearchText(text) + } const {data: autocompleteData, isFetching: isAutocompleteFetching} = useActorAutocompleteQuery(searchText, true)