fix: too many re-renders when toggling experimental feed sampling option (#10114)
(cherry picked from commit 894e2b89d4)
This commit is contained in:
committed by
Eric Bailey
parent
8ceec4c33b
commit
0d8b9d9c6a
Vendored
+14
-14
@@ -134,22 +134,22 @@ export function usePostAuthorShadowFilter(data?: FeedPage[]) {
|
|||||||
new Map<string, {muted: boolean; blocked: boolean}>(),
|
new Map<string, {muted: boolean; blocked: boolean}>(),
|
||||||
)
|
)
|
||||||
|
|
||||||
const [prevData, setPrevData] = useState(data)
|
useEffect(() => {
|
||||||
if (data !== prevData) {
|
setTrackedDids(prev => {
|
||||||
const newAuthors = new Set(trackedDids)
|
const currentDids = new Set(prev)
|
||||||
let hasNew = false
|
let hasNew = false
|
||||||
for (const slice of data?.flatMap(page => page.slices) ?? []) {
|
for (const slice of data?.flatMap(page => page.slices) ?? []) {
|
||||||
for (const item of slice.items) {
|
for (const item of slice.items) {
|
||||||
const author = item.post.author
|
const author = item.post.author
|
||||||
if (!newAuthors.has(author.did)) {
|
if (!currentDids.has(author.did)) {
|
||||||
hasNew = true
|
hasNew = true
|
||||||
newAuthors.add(author.did)
|
currentDids.add(author.did)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return hasNew ? [...currentDids] : prev
|
||||||
if (hasNew) setTrackedDids([...newAuthors])
|
})
|
||||||
setPrevData(data)
|
}, [data])
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const unsubs: Array<() => void> = []
|
const unsubs: Array<() => void> = []
|
||||||
|
|||||||
Reference in New Issue
Block a user