From f37b5592fd3d02179669fe1d0358a500fb9f651a Mon Sep 17 00:00:00 2001 From: James Xylight Date: Sun, 3 Aug 2025 10:07:18 -0700 Subject: [PATCH] fix: duplicate posts in feeds --- .../lemmy/post/feed/VirtualFeed.svelte | 46 ++++++++++++------- src/lib/i18n/en.json | 6 ++- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/lib/components/lemmy/post/feed/VirtualFeed.svelte b/src/lib/components/lemmy/post/feed/VirtualFeed.svelte index 71fd3141..5d59779d 100644 --- a/src/lib/components/lemmy/post/feed/VirtualFeed.svelte +++ b/src/lib/components/lemmy/post/feed/VirtualFeed.svelte @@ -14,13 +14,13 @@ import { settings } from '$lib/settings.svelte.js' import type { PostView } from 'lemmy-js-client' import { Button } from 'mono-svelte' - import { onMount, untrack } from 'svelte' + import { onDestroy, onMount, untrack } from 'svelte' import { ArchiveBox, + ArrowTopRightOnSquare, ChevronDoubleUp, ExclamationTriangle, Icon, - Plus, } from 'svelte-hero-icons' import InfiniteScroll from 'svelte-infinite-scroll' @@ -49,14 +49,20 @@ let loading = $state(false) let hasMore = $state(true) + const abortLoad = new AbortController() + async function loadMore() { - console.log(hasMore, loading) if (!hasMore || loading) return try { loading = true - const newPosts = await client() + console.log('fetching with cursor', feedData.cursor.next) + + const newPosts = await client({ + func: (input, init) => + fetch(input, { ...init, signal: abortLoad.signal }), + }) .getPosts({ page_cursor: feedData.cursor.next, disliked_only: feedData.disliked_only, @@ -78,6 +84,15 @@ hasMore = newPosts.posts.length != 0 + let postIds: number[] = [] + let duplicates: number[] = [] + for (const post of newPosts.posts) { + if (postIds.includes(post.post.id)) duplicates.push(post.post.id) + else postIds.push(post.post.id) + } + + console.log('are there duplicates?', duplicates) + feedData.cursor.next = newPosts.next_page feedData.posts.posts.push(...newPosts.posts) @@ -150,6 +165,10 @@ }) let initialOffset = $derived(listEl?.offsetTop) + + onDestroy(() => { + abortLoad?.abort() + }) diff --git a/src/lib/i18n/en.json b/src/lib/i18n/en.json index dea0246f..4318059e 100644 --- a/src/lib/i18n/en.json +++ b/src/lib/i18n/en.json @@ -213,7 +213,11 @@ "frontpage": { "title": "Frontpage", "footer": "{{users:number}} active {{users; 1:user; default:users;}}", - "endFeed": "You have reached the end of {{community_name; undefined:the feed.; default:{{community_name}}.}}" + "endFeed": "You have reached the end of {{community_name; undefined:the feed.; default:{{community_name}}.}}", + "empty": { + "title": "No posts", + "description": "There are no posts that match this filter." + } }, "modlog": { "title": "Modlog",