From e03527ba78ca3ce6372a94cf3a953133e201565a Mon Sep 17 00:00:00 2001 From: "shakespeare.diy" Date: Wed, 18 Feb 2026 15:43:23 -0600 Subject: [PATCH] Fix infinite scroll race condition and add relay logging Infinite scroll fixes: - Allow boundaries within 2 pages of end to trigger (not just last page) - Prevents race where scrolling fast skips page boundaries - Reduced rootMargin from 800px to 400px for more controlled loading - Pages can trigger next load even if not technically "last" yet Profile loading debug: - Log which relays are being queried in loser's race - Helps debug why profiles aren't loading (missing relays like nos.lol) Co-authored-by: shakespeare.diy --- src/components/Feed.tsx | 14 ++++++++++---- src/hooks/useAuthors.ts | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/components/Feed.tsx b/src/components/Feed.tsx index 1e338759..087668c7 100644 --- a/src/components/Feed.tsx +++ b/src/components/Feed.tsx @@ -215,14 +215,20 @@ function PageBoundary({ }) { const { ref, inView } = useInView({ threshold: 0, - rootMargin: '800px', // Start loading well before the user reaches this page + rootMargin: '400px', // Start loading before the user reaches this page }); useEffect(() => { - // Trigger next page when this page comes into view + // Trigger next page when ANY page boundary comes into view (not just the last one) + // This prevents race conditions when scrolling fast // Skip page 0 since it auto-loads page 1 - if (inView && pageIndex > 0 && pageIndex === totalPages - 1 && hasNextPage && !isFetchingNextPage) { - onLoadNext(); + if (inView && pageIndex > 0 && hasNextPage && !isFetchingNextPage) { + // Only trigger if this is the last page, OR if we're close to it (within 1 page) + // This prevents triggering page 10 when we're only on page 2 + const isRelevant = pageIndex >= totalPages - 2; + if (isRelevant) { + onLoadNext(); + } } }, [inView, pageIndex, totalPages, hasNextPage, isFetchingNextPage, onLoadNext]); diff --git a/src/hooks/useAuthors.ts b/src/hooks/useAuthors.ts index 60addb24..58b0904f 100644 --- a/src/hooks/useAuthors.ts +++ b/src/hooks/useAuthors.ts @@ -69,7 +69,7 @@ export function useAuthors(pubkeys: string[]) { // individually with more time (5000ms vs 500ms EOSE timeout). const missing = uniquePubkeys.filter(pk => !found.has(pk)); if (missing.length > 0 && readRelayUrls.length > 0) { - console.log('[useAuthors] Loser race for', missing.length, 'missing profiles on', readRelayUrls.length, 'relays'); + console.log('[useAuthors] Loser race for', missing.length, 'missing profiles on', readRelayUrls.length, 'relays:', readRelayUrls); await new Promise((resolve) => { const needed = new Set(missing); let pending = readRelayUrls.length;