perf(feeds): use hasMore instead of length check for conditional virtualization

This commit is contained in:
plebeius
2026-01-13 17:01:51 +01:00
parent 80100fa54d
commit c0c6e9ee31
5 changed files with 54 additions and 34 deletions
+22 -12
View File
@@ -381,18 +381,28 @@ const Board = ({ feedCacheKey, viewType, boardIdentifier: boardIdentifierProp, t
<ErrorDisplay error={subplebbitError} />
</div>
)}
<Virtuoso
increaseViewportBy={{ bottom: 1200, top: 1200 }}
totalCount={combinedFeed.length}
data={combinedFeed}
itemContent={(index, post) => <Post index={index} post={post} />}
useWindowScroll={true}
components={{ Footer }}
endReached={loadMore}
ref={virtuosoRef}
restoreStateFrom={lastVirtuosoState}
initialScrollTop={lastVirtuosoState?.scrollTop}
/>
{/* Use Virtuoso for infinite scroll only when there's more content to paginate */}
{hasMore ? (
<Virtuoso
increaseViewportBy={{ bottom: 1200, top: 1200 }}
totalCount={combinedFeed.length}
data={combinedFeed}
itemContent={(index, post) => <Post index={index} post={post} />}
useWindowScroll={true}
components={{ Footer }}
endReached={loadMore}
ref={virtuosoRef}
restoreStateFrom={lastVirtuosoState}
initialScrollTop={lastVirtuosoState?.scrollTop}
/>
) : (
<>
{combinedFeed.map((post, index) => (
<Post key={post.cid} index={index} post={post} />
))}
<Footer />
</>
)}
</div>
</>
);
+22 -12
View File
@@ -540,18 +540,28 @@ const Catalog = ({ feedCacheKey, viewType, boardIdentifier: boardIdentifierProp,
<div className={styles.catalog}>
{processedFeed?.length !== 0 ? (
<>
<Virtuoso
increaseViewportBy={{ bottom: 1200, top: 1200 }}
totalCount={rows?.length || 0}
data={rows}
itemContent={(index, row) => <CatalogRow index={index} row={row} />}
useWindowScroll={true}
components={{ Footer }}
endReached={loadMore}
ref={virtuosoRef}
restoreStateFrom={lastVirtuosoState}
initialScrollTop={lastVirtuosoState?.scrollTop}
/>
{/* Use Virtuoso for infinite scroll only when there's more content to paginate */}
{hasMore ? (
<Virtuoso
increaseViewportBy={{ bottom: 1200, top: 1200 }}
totalCount={rows?.length || 0}
data={rows}
itemContent={(index, row) => <CatalogRow index={index} row={row} />}
useWindowScroll={true}
components={{ Footer }}
endReached={loadMore}
ref={virtuosoRef}
restoreStateFrom={lastVirtuosoState}
initialScrollTop={lastVirtuosoState?.scrollTop}
/>
) : (
<>
{rows.map((row, index) => (
<CatalogRow key={index} index={index} row={row} />
))}
<Footer />
</>
)}
</>
) : (
<div className={styles.footer}>
+2 -2
View File
@@ -632,8 +632,8 @@ export const ModQueueView = ({ boardIdentifier: propBoardIdentifier }: ModQueueV
<div className={styles.actionsHeader}>{t('actions')}</div>
</div>
{/* Use Virtuoso for infinite scroll only when feed is large enough to warrant it */}
{feed.length > 25 ? (
{/* Use Virtuoso for infinite scroll only when there's more content to paginate */}
{hasMore ? (
<Virtuoso
useWindowScroll
data={feed}