diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-12-27 08:49:39 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-27 08:49:39 -0800 |
commit | 8b6ecf6bfff0a18e92a172004cd37fe2aacaf37f (patch) | |
tree | 4ee431b5c96c1cb3c9e02288b8ad48c2736d6a3a /src | |
parent | 0c9dc2163ab5102e58f13597ba84e14717e09ffd (diff) | |
download | voidsky-8b6ecf6bfff0a18e92a172004cd37fe2aacaf37f.tar.zst |
* Fix duplicate react keys in post search * Protect against duplicate react keys in feeds
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/api/feed-manip.ts | 19 | ||||
-rw-r--r-- | src/view/screens/Search/Search.tsx | 5 |
2 files changed, 15 insertions, 9 deletions
diff --git a/src/lib/api/feed-manip.ts b/src/lib/api/feed-manip.ts index 9a050fd3e..c964693c4 100644 --- a/src/lib/api/feed-manip.ts +++ b/src/lib/api/feed-manip.ts @@ -117,11 +117,7 @@ export class FeedViewPostsSlice { } export class NoopFeedTuner { - private keyCounter = 0 - - reset() { - this.keyCounter = 0 - } + reset() {} tune( feed: FeedViewPost[], _opts?: {dryRun: boolean; maintainOrder: boolean}, @@ -131,13 +127,13 @@ export class NoopFeedTuner { } export class FeedTuner { - private keyCounter = 0 + seenKeys: Set<string> = new Set() seenUris: Set<string> = new Set() constructor(public tunerFns: FeedTunerFn[]) {} reset() { - this.keyCounter = 0 + this.seenKeys.clear() this.seenUris.clear() } @@ -218,11 +214,16 @@ export class FeedTuner { } if (!dryRun) { - for (const slice of slices) { + slices = slices.filter(slice => { + if (this.seenKeys.has(slice._reactKey)) { + return false + } for (const item of slice.items) { this.seenUris.add(item.post.uri) } - } + this.seenKeys.add(slice._reactKey) + return true + }) } return slices diff --git a/src/view/screens/Search/Search.tsx b/src/view/screens/Search/Search.tsx index 60fd21674..b522edfba 100644 --- a/src/view/screens/Search/Search.tsx +++ b/src/view/screens/Search/Search.tsx @@ -212,12 +212,17 @@ function SearchScreenPostResults({query}: {query: string}) { const items = React.useMemo(() => { let temp: SearchResultSlice[] = [] + const seenUris = new Set() for (const post of posts) { + if (seenUris.has(post.uri)) { + continue + } temp.push({ type: 'post', key: post.uri, post, }) + seenUris.add(post.uri) } if (isFetchingNextPage) { |