From 68057628342daac8107752e566f0d118c897fa1d Mon Sep 17 00:00:00 2001 From: litruv Date: Sun, 1 Nov 2026 10:48:55 +1100 Subject: [PATCH] Drop autofocus and move the search reset out of render. [skip build] --- src/app/features/forum/ForumNewPostModal.tsx | 1 - src/app/hooks/useAsyncSearch.ts | 14 +++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/app/features/forum/ForumNewPostModal.tsx b/src/app/features/forum/ForumNewPostModal.tsx index 1cd3155a..7a1f0df9 100644 --- a/src/app/features/forum/ForumNewPostModal.tsx +++ b/src/app/features/forum/ForumNewPostModal.tsx @@ -275,7 +275,6 @@ export function ForumNewPostModal({ onChange={(e) => setTitle(e.target.value)} maxLength={140} required - autoFocus placeholder="Title" aria-label="Title" autoComplete="off" diff --git a/src/app/hooks/useAsyncSearch.ts b/src/app/hooks/useAsyncSearch.ts index 8518a8bd..84b4d8f0 100644 --- a/src/app/hooks/useAsyncSearch.ts +++ b/src/app/hooks/useAsyncSearch.ts @@ -112,8 +112,6 @@ export const useAsyncSearch = ( const [result, setResult] = useState>(); const [searchCallback, terminateSearch] = useMemo(() => { - setResult(undefined); - const handleMatch: MatchHandler = (item, query) => { const itemStr = getItemStr(item, query); @@ -143,13 +141,15 @@ export const useAsyncSearch = ( setResult(undefined); }, [terminateSearch]); - useEffect( - () => () => { + useEffect(() => { + // clear stale results whenever the search source is recreated + setResult(undefined); + + return () => { // terminate any ongoing search request on unmount. terminateSearch(); - }, - [terminateSearch], - ); + }; + }, [terminateSearch]); return [result, searchHandler, resetHandler]; };