Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix search query autocomplete lagging behind (#10381)

authored by

Evan and committed by
GitHub
8bfce096 28327459

+21 -11
+21 -11
src/components/Autocomplete/useAutocomplete/index.ts
··· 1 - import {useCallback} from 'react' 1 + import {useCallback, useMemo} from 'react' 2 2 import {moderateProfile, type ModerationOpts} from '@atproto/api' 3 3 import {keepPreviousData, useQuery} from '@tanstack/react-query' 4 4 ··· 90 90 } 91 91 } 92 92 93 - if (showSearchFallback && q) { 94 - results.unshift({ 95 - key: `search-${q}`, 96 - type: 'search' as const, 97 - value: q, 98 - }) 99 - } 100 - 101 93 return results 102 94 }, 103 - [q, showSearchFallback, moderationOpts], 95 + [q, moderationOpts], 104 96 ), 105 97 placeholderData: keepPreviousData, 106 98 }) 107 99 100 + const items = useMemo(() => { 101 + if (!query.data) { 102 + return [] 103 + } 104 + 105 + const results = [...query.data] 106 + 107 + if (showSearchFallback && q) { 108 + results.unshift({ 109 + key: `search-${q}`, 110 + type: 'search' as const, 111 + value: q, 112 + }) 113 + } 114 + 115 + return results 116 + }, [query.data, showSearchFallback, q]) 117 + 108 118 return { 109 119 query: q, 110 - items: query.data || [], 120 + items, 111 121 } 112 122 } 113 123