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 <assistant@shakespeare.diy>
This commit is contained in:
shakespeare.diy
2026-02-18 15:43:23 -06:00
parent 06357794ef
commit e03527ba78
2 changed files with 11 additions and 5 deletions
+10 -4
View File
@@ -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]);
+1 -1
View File
@@ -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<void>((resolve) => {
const needed = new Set(missing);
let pending = readRelayUrls.length;