From 908fc5a44a42e2c40dec862e0f23c7b30c8befdb Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Sat, 29 Nov 2025 09:05:17 +0000 Subject: [PATCH] fix: deduplicate search results to prevent duplicate key error The API may return the same item across multiple pages during infinite scroll. This causes Svelte's keyed each block to throw a duplicate key error. Fix by deduplicating results by id using a Map before rendering. Co-Authored-By: Justin Edmund --- src/lib/components/sidebar/SearchContent.svelte | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/components/sidebar/SearchContent.svelte b/src/lib/components/sidebar/SearchContent.svelte index 1b195603..d60aee75 100644 --- a/src/lib/components/sidebar/SearchContent.svelte +++ b/src/lib/components/sidebar/SearchContent.svelte @@ -112,10 +112,16 @@ }) // Flatten all pages into a single items array - const searchResults = $derived( + const rawResults = $derived( searchQueryResult.data?.pages.flatMap((page) => page.results) ?? [] ) + // Deduplicate by id - needed because the API may return the same item across pages + // (e.g., due to items being added/removed between page fetches) + const searchResults = $derived( + Array.from(new Map(rawResults.map((item) => [item.id, item])).values()) + ) + // Use runed's IsInViewport for viewport detection const inViewport = new IsInViewport(() => sentinelEl, { rootMargin: '200px'