From 894e2b89d4fc46190bb9491c4f3c781f33a57ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Fornagiel?= <85541429+pFornagiel@users.noreply.github.com> Date: Tue, 24 Mar 2026 20:59:01 +0100 Subject: [PATCH] fix: too many re-renders when toggling experimental feed sampling option (#10114) --- src/state/cache/profile-shadow.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/state/cache/profile-shadow.ts b/src/state/cache/profile-shadow.ts index 2308316c9b..34422dc0c0 100644 --- a/src/state/cache/profile-shadow.ts +++ b/src/state/cache/profile-shadow.ts @@ -134,22 +134,22 @@ export function usePostAuthorShadowFilter(data?: FeedPage[]) { new Map(), ) - const [prevData, setPrevData] = useState(data) - if (data !== prevData) { - const newAuthors = new Set(trackedDids) - let hasNew = false - for (const slice of data?.flatMap(page => page.slices) ?? []) { - for (const item of slice.items) { - const author = item.post.author - if (!newAuthors.has(author.did)) { - hasNew = true - newAuthors.add(author.did) + useEffect(() => { + setTrackedDids(prev => { + const currentDids = new Set(prev) + let hasNew = false + for (const slice of data?.flatMap(page => page.slices) ?? []) { + for (const item of slice.items) { + const author = item.post.author + if (!currentDids.has(author.did)) { + hasNew = true + currentDids.add(author.did) + } } } - } - if (hasNew) setTrackedDids([...newAuthors]) - setPrevData(data) - } + return hasNew ? [...currentDids] : prev + }) + }, [data]) useEffect(() => { const unsubs: Array<() => void> = []