From 23b9ca58c01366d85b7c45d139be7d5267f2e0e1 Mon Sep 17 00:00:00 2001 From: Chad Curtis Date: Sat, 4 Oct 2025 17:05:52 +0000 Subject: [PATCH] Add deduplication to infinite feed scroll example This change introduces a simple deduplication mechanicsm for the example infinite scroll feed code we provide for the agent. I have also added a 'isFetchingNextPage' check to avoid the potential scenario of aggressively overfetching via quick scrolling. If a post exists in the feed already (it has been 'seen'), the it and all duplicate post events will be filtered out from the returned content. --- docs/NOSTR_INFINITE_SCROLL.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/NOSTR_INFINITE_SCROLL.md b/docs/NOSTR_INFINITE_SCROLL.md index d183f26..becee36 100644 --- a/docs/NOSTR_INFINITE_SCROLL.md +++ b/docs/NOSTR_INFINITE_SCROLL.md @@ -34,18 +34,27 @@ Example usage with intersection observer for automatic loading: ```tsx import { useInView } from 'react-intersection-observer'; +import { useMemo } from 'react'; function GlobalFeed() { const { data, fetchNextPage, hasNextPage, isFetchingNextPage } = useGlobalFeed(); const { ref, inView } = useInView(); useEffect(() => { - if (inView && hasNextPage) { + if (inView && hasNextPage && !isFetchingNextPage) { fetchNextPage(); } - }, [inView, hasNextPage, fetchNextPage]); + }, [inView, hasNextPage, isFetchingNextPage, fetchNextPage]); - const posts = data?.pages.flat() || []; + // Remove duplicate events by ID + const posts = useMemo(() => { + const seen = new Set(); + return data?.pages.flat().filter(event => { + if (!event.id || seen.has(event.id)) return false; + seen.add(event.id); + return true; + }) || []; + }, [data?.pages]); return (