From a055f18cc351b445902829131b1ca0e8a3df6567 Mon Sep 17 00:00:00 2001 From: vineyardbovines Date: Tue, 14 Jul 2026 16:44:24 -0400 Subject: [PATCH] sort recent profiles by history recency --- src/features/searchHistory/index.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/features/searchHistory/index.ts b/src/features/searchHistory/index.ts index d1193941c6..3dee7c9e12 100644 --- a/src/features/searchHistory/index.ts +++ b/src/features/searchHistory/index.ts @@ -16,7 +16,8 @@ const MAX_PROFILES = 10 * Per-account recent search history (device storage). Terms are stored as * serialized history entries (plain string, or JSON when filters are * attached); profiles are stored as DIDs and hydrated via useProfilesQuery, - * which keeps avatars/names fresh (stale-while-revalidate). + * which keeps avatars/names fresh (stale-while-revalidate). Both lists are + * ordered most-recent-first. */ export function useSearchHistory() { const {currentAccount} = useSession() @@ -34,10 +35,13 @@ export function useSearchHistory() { maintainData: true, }) - const profiles = - accountHistoryProfiles?.profiles.filter(p => - accountHistory.includes(p.did), - ) ?? [] + /* + * getProfiles response order is not guaranteed, so map over accountHistory + * to preserve most-recent-first order (and drop entries not yet hydrated). + */ + const profiles = accountHistory + .map(did => accountHistoryProfiles?.profiles.find(p => p.did === did)) + .filter(p => p !== undefined) const updateSearchHistory = useCallback( (q: string, searchFilters: SearchFilters = {}) => {