From bfe6852ae73fb21be48ae1954e0b3e99c2de8dd5 Mon Sep 17 00:00:00 2001 From: Rajat Dabade Date: Mon, 14 Jul 2025 18:03:24 +0530 Subject: [PATCH] Fix stale search results when files are deleted from posts (#8985) * Fix stale search results when files are deleted from posts * Minor * cleaned the dependency from useDidUpdate to not trigger unnecessary API call * Added comment --- app/screens/home/search/search.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/screens/home/search/search.tsx b/app/screens/home/search/search.tsx index 7209dc413..445160778 100644 --- a/app/screens/home/search/search.tsx +++ b/app/screens/home/search/search.tsx @@ -374,6 +374,19 @@ const SearchScreen = ({teamId, teams, crossTeamSearchEnabled}: Props) => { } }, [isFocused]); + useDidUpdate(() => { + if (isFocused && lastSearchedValue && showResults) { + // requestAnimationFrame for smooth UI updates + requestAnimationFrame(() => { + handleSearch(searchTeamId, lastSearchedValue); + }); + } + + // Only watch isFocused to re-run search when screen comes back into focus + // Removed lastSearchedValue, showResults, handleSearch, searchTeamId from dependencies + // to prevent duplicate search calls (these values are updated by handleSearch itself) + }, [isFocused]); + const handleEnterPressed = useCallback(() => { const topScreen = NavigationStore.getVisibleScreen(); if (topScreen === Screens.HOME && isFocused) {