From 484b326b9ff77ae70c3448924c2fe2bb29b9c2a9 Mon Sep 17 00:00:00 2001 From: "Timothy Z." Date: Mon, 27 Jul 2026 20:38:16 +0300 Subject: [PATCH] fix: stop repeated Discover auto-pagination --- src/routes/Discover/Discover.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/routes/Discover/Discover.js b/src/routes/Discover/Discover.js index 3f1294550..0124cefb9 100644 --- a/src/routes/Discover/Discover.js +++ b/src/routes/Discover/Discover.js @@ -38,21 +38,30 @@ const Discover = () => { const metasContainerRef = React.useRef(); const metaPreviewRef = React.useRef(); + const previousCatalogSizeRef = React.useRef(0); React.useEffect(() => { if (discover.catalog?.content.type === 'Loading') { metasContainerRef.current.scrollTop = 0; + previousCatalogSizeRef.current = 0; } }, [discover.catalog]); React.useEffect(() => { - if (hasNextPage && metasContainerRef.current) { + if (discover.catalog?.content.type === 'Ready') { + const catalogSize = discover.catalog.content.content.length; + const hasNewItems = catalogSize > previousCatalogSizeRef.current; + previousCatalogSizeRef.current = catalogSize; + if (!hasNextPage || !hasNewItems || !metasContainerRef.current) { + return; + } + const containerHeight = metasContainerRef.current.scrollHeight; const viewportHeight = metasContainerRef.current.clientHeight; if (containerHeight <= viewportHeight + SCROLL_TO_BOTTOM_THRESHOLD) { loadNextPage(); } } - }, [hasNextPage, loadNextPage]); + }, [discover.catalog, hasNextPage, loadNextPage]); const addToLibrary = React.useCallback(() => { if (selectedMetaItem === null) { return;