* Fix duplicate react keys in post search * Protect against duplicate react keys in feeds
This commit is contained in:
parent
0c9dc2163a
commit
8b6ecf6bff
2 changed files with 15 additions and 9 deletions
|
@ -117,11 +117,7 @@ export class FeedViewPostsSlice {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class NoopFeedTuner {
|
export class NoopFeedTuner {
|
||||||
private keyCounter = 0
|
reset() {}
|
||||||
|
|
||||||
reset() {
|
|
||||||
this.keyCounter = 0
|
|
||||||
}
|
|
||||||
tune(
|
tune(
|
||||||
feed: FeedViewPost[],
|
feed: FeedViewPost[],
|
||||||
_opts?: {dryRun: boolean; maintainOrder: boolean},
|
_opts?: {dryRun: boolean; maintainOrder: boolean},
|
||||||
|
@ -131,13 +127,13 @@ export class NoopFeedTuner {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FeedTuner {
|
export class FeedTuner {
|
||||||
private keyCounter = 0
|
seenKeys: Set<string> = new Set()
|
||||||
seenUris: Set<string> = new Set()
|
seenUris: Set<string> = new Set()
|
||||||
|
|
||||||
constructor(public tunerFns: FeedTunerFn[]) {}
|
constructor(public tunerFns: FeedTunerFn[]) {}
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
this.keyCounter = 0
|
this.seenKeys.clear()
|
||||||
this.seenUris.clear()
|
this.seenUris.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,11 +214,16 @@ export class FeedTuner {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dryRun) {
|
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) {
|
for (const item of slice.items) {
|
||||||
this.seenUris.add(item.post.uri)
|
this.seenUris.add(item.post.uri)
|
||||||
}
|
}
|
||||||
}
|
this.seenKeys.add(slice._reactKey)
|
||||||
|
return true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return slices
|
return slices
|
||||||
|
|
|
@ -212,12 +212,17 @@ function SearchScreenPostResults({query}: {query: string}) {
|
||||||
const items = React.useMemo(() => {
|
const items = React.useMemo(() => {
|
||||||
let temp: SearchResultSlice[] = []
|
let temp: SearchResultSlice[] = []
|
||||||
|
|
||||||
|
const seenUris = new Set()
|
||||||
for (const post of posts) {
|
for (const post of posts) {
|
||||||
|
if (seenUris.has(post.uri)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
temp.push({
|
temp.push({
|
||||||
type: 'post',
|
type: 'post',
|
||||||
key: post.uri,
|
key: post.uri,
|
||||||
post,
|
post,
|
||||||
})
|
})
|
||||||
|
seenUris.add(post.uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFetchingNextPage) {
|
if (isFetchingNextPage) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue