Fix stale search results when files are deleted from posts (#8985) (#8992)

* Fix stale search results when files are deleted from posts

* Minor

* cleaned the  dependency from useDidUpdate to not trigger unnecessary API call

* Added comment

(cherry picked from commit bfe6852ae7)

Co-authored-by: Rajat Dabade <rajatdabade1997@gmail.com>
This commit is contained in:
Mattermost Build 2025-07-14 16:13:17 +03:00 committed by GitHub
parent 74c5a84c0c
commit 46ca08b939
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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) {