From a07787c2c63fff9d87c06683eaa3907a47e52d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Tue, 16 Jun 2026 09:22:48 +0200 Subject: [PATCH] Fix patches list pagination The patches list paged through everything without scrolling: ScrollArea fired its load-more check on every `updated` DOM event, and the list's min-height made the bottom threshold always true, so each appended page triggered the next. Move it to InfiniteScrollSentinel like the commits list. --- src/components/ScrollArea.svelte | 29 +------- src/views/repo/Layout.svelte | 19 +---- src/views/repo/Patches.svelte | 117 +++++++++++++++++-------------- 3 files changed, 68 insertions(+), 97 deletions(-) diff --git a/src/components/ScrollArea.svelte b/src/components/ScrollArea.svelte index 4ecef967f..f8dc28411 100644 --- a/src/components/ScrollArea.svelte +++ b/src/components/ScrollArea.svelte @@ -20,36 +20,12 @@ interface Props { children: Snippet; style?: string; - onScrollHalf?: () => void; } - const { - children, - style = "height: 100%;", - onScrollHalf = undefined, - }: Props = $props(); + const { children, style = "height: 100%;" }: Props = $props(); let viewport: HTMLElement | undefined = $state(undefined); setContext(SCROLL_VIEWPORT_CONTEXT, () => viewport); - - function shouldLoadMore(instance: { - elements(): { target: HTMLElement }; - }): boolean { - const el = instance.elements().target; - const threshold = 200; - - return el.scrollTop + el.clientHeight >= el.scrollHeight - threshold; - } - - const scrollHalfHandler = $derived( - onScrollHalf - ? (instance: Parameters[0]) => { - if (shouldLoadMore(instance)) { - onScrollHalf(); - } - } - : undefined, - ); { viewport = instance.elements().viewport; - scrollHalfHandler?.(instance); }, - scroll: scrollHalfHandler, - updated: scrollHalfHandler, }} defer> {@render children()} diff --git a/src/views/repo/Layout.svelte b/src/views/repo/Layout.svelte index 62955b96b..34e43cb35 100644 --- a/src/views/repo/Layout.svelte +++ b/src/views/repo/Layout.svelte @@ -5,17 +5,10 @@ interface Props { children: Snippet; - loadMoreContent?: () => Promise; selfScroll?: boolean; } - const { - children, - loadMoreContent = undefined, - selfScroll = false, - }: Props = $props(); - - let loadingContent = false; + const { children, selfScroll = false }: Props = $props(); {#if selfScroll} @@ -25,15 +18,7 @@ {:else} { - if (!loadingContent) { - loadingContent = true; - void loadMoreContent().finally(() => (loadingContent = false)); - } - } - : undefined}> + style="height: 100%; width: 100%; background-color: var(--color-surface-canvas);"> {@render children()} {/if} diff --git a/src/views/repo/Patches.svelte b/src/views/repo/Patches.svelte index dceb5cc9d..f56db4ed7 100644 --- a/src/views/repo/Patches.svelte +++ b/src/views/repo/Patches.svelte @@ -11,6 +11,7 @@ import delay from "lodash/delay"; import { invoke } from "@app/lib/invoke"; + import * as mutexExecutor from "@app/lib/mutexExecutor"; import { patchCountMismatch, resetPatchCounts, @@ -22,6 +23,7 @@ import CobCacheWarning from "@app/components/CobCacheWarning.svelte"; import FuzzySearch from "@app/components/FuzzySearch.svelte"; import Icon from "@app/components/Icon.svelte"; + import InfiniteScrollSentinel from "@app/components/InfiniteScrollSentinel.svelte"; import NewPatchButton from "@app/components/NewPatchButton.svelte"; import PatchTeaser from "@app/components/PatchTeaser.svelte"; import ScrollArea from "@app/components/ScrollArea.svelte"; @@ -42,22 +44,25 @@ // svelte-ignore state_referenced_locally let items = $state(patches.content); // svelte-ignore state_referenced_locally - let cursor = patches.cursor; - // svelte-ignore state_referenced_locally - let more = patches.more; + let more = $state(patches.more); + let loadingMore = $state(false); + let loading = $state(false); + let searchInput = $state(""); + let debouncedSearch = $state(""); + let showSearch = $state(false); + let cacheState: CacheEvent | undefined = $state(); const project = $derived(repo.payloads["xyz.radicle.project"]!); - let cacheState: CacheEvent | undefined = $state(); + const loader = mutexExecutor.create(); + const abort = async (): Promise => undefined; $effect(() => { items = patches.content; - cursor = patches.cursor; - if (patches.more === true && patches.content.length < DEFAULT_TAKE) { - more = false; - } else { - more = patches.more; - } + more = patches.more; + // Abort any in-flight loadMoreContent so it cannot append a page + // from the previous filter onto the just-reset items. + void loader.run(abort); }); $effect(() => { @@ -74,6 +79,14 @@ showSearch = false; }); + $effect(() => { + const value = searchInput; + const timer = setTimeout(() => { + debouncedSearch = value; + }, 150); + return () => clearTimeout(timer); + }); + async function rebuildPatchCache() { try { await invoke("rebuild_patch_cache", { @@ -85,16 +98,19 @@ } catch (error) { console.error(error); } finally { - const p = await invoke>("list_patches", { - rid: repo.rid, - skip: 0, - status, - take: DEFAULT_TAKE, + const page = await loader.run(async () => { + return await invoke>("list_patches", { + rid: repo.rid, + skip: 0, + status, + take: DEFAULT_TAKE, + }); }); - items = p.content; - cursor = p.cursor; - more = p.more; + if (page !== undefined) { + items = page.content; + more = page.more; + } resetPatchCounts(); @@ -104,39 +120,39 @@ } } - async function loadMoreContent(all: boolean = false) { - if (more) { - const p = await invoke>("list_patches", { - rid: repo.rid, - skip: cursor + DEFAULT_TAKE, - status, - take: all ? undefined : DEFAULT_TAKE, + async function loadMoreContent(all: boolean = false): Promise { + if (!more) return; + loadingMore = true; + let superseded = false; + try { + const page = await loader.run(async () => { + return await invoke>("list_patches", { + rid: repo.rid, + status, + skip: all ? 0 : items.length, + take: all ? undefined : DEFAULT_TAKE, + }); }); - cursor = p.cursor; - more = p.more; - - if (all) { - items = p.content; - } else { - items = [...items, ...p.content]; + // Superseded by a newer load (e.g. fuzzy-focus triggered a load-all). + // Leave items/more alone for the new call. The flag stays set too: the + // newer call owns it now, and clearing it here would let the + // virtualizer's auto load-more re-fire and abort that call in turn. + if (page === undefined) { + superseded = true; + return; } - if (p.content.length === 0) { - more = false; - } - - if (more === false) { - updatePatchCounts(items.length, project.meta.patches, status); + more = page.more; + items = all ? page.content : [...items, ...page.content]; + if (page.content.length === 0) more = false; + } finally { + if (!superseded) { + loadingMore = false; } } } - let loadingMore: boolean = $state(false); - let loading: boolean = $state(false); - let searchInput = $state(""); - let showSearch = $state(false); - const searchablePatches = $derived( items .flatMap(i => { @@ -155,7 +171,7 @@ ); const searchResults = $derived( - fuzzysort.go(searchInput, searchablePatches, { + fuzzysort.go(debouncedSearch, searchablePatches, { keys: ["patch.title", "labels", "assignees", "author", "patch.id"], threshold: 0.5, all: true, @@ -327,14 +343,7 @@ - { - if (!loadingMore) { - loadingMore = true; - void loadMoreContent().finally(() => (loadingMore = false)); - } - }}> + {#if patchCountMismatch(status)} {/if} + +