perf(feed): reduce Virtuoso overscan and memoize itemContent for multiboard views

This commit is contained in:
plebeius
2026-02-26 17:27:58 +08:00
parent 6ac9ac0ee7
commit 6e08203ce6
3 changed files with 9 additions and 7 deletions
+5 -3
View File
@@ -1,4 +1,4 @@
import { useEffect, useMemo, useRef } from 'react';
import { useCallback, useEffect, useMemo, useRef } from 'react';
import { useLocation, useNavigate, useNavigationType, useParams } from 'react-router-dom';
import { Comment, useAccount, useAccountComments, useAccountSubplebbits, useFeed, useSubplebbit } from '@plebbit/plebbit-react-hooks';
import { useSubplebbitField } from '../../hooks/use-stable-subplebbit';
@@ -291,6 +291,8 @@ const Board = ({ feedCacheKey, viewType, boardIdentifier: boardIdentifierProp, i
const virtuosoStateKey = feedCacheKey ? `${feedCacheKey}-${BOARD_SORT_TYPE}` : `${location.pathname}-${BOARD_SORT_TYPE}`;
const navigationType = useNavigationType();
const boardItemContent = useCallback((index: number, post: Comment | undefined) => <Post index={index} post={post} />, []);
const hasBeenVisibleRef = useRef(false);
useEffect(() => {
if (isVisible && !hasBeenVisibleRef.current) {
@@ -353,11 +355,11 @@ const Board = ({ feedCacheKey, viewType, boardIdentifier: boardIdentifierProp, i
{effectiveInfiniteScroll ? (
<Virtuoso
defaultItemHeight={300}
increaseViewportBy={{ bottom: 1200, top: 1200 }}
increaseViewportBy={isInAllView || isInSubscriptionsView || isInModView ? { bottom: 600, top: 600 } : { bottom: 1200, top: 1200 }}
totalCount={displayFeed.length}
data={displayFeed}
computeItemKey={(index, post) => post?.cid || `post-${index}`}
itemContent={(index, post) => <Post index={index} post={post} />}
itemContent={boardItemContent}
useWindowScroll={true}
components={footerComponents}
endReached={hasMore ? loadMore : undefined}
+1 -1
View File
@@ -503,7 +503,7 @@ const Catalog = ({ feedCacheKey, viewType, boardIdentifier: boardIdentifierProp,
<>
<Virtuoso
defaultItemHeight={imageSize === 'Large' ? 320 : 200}
increaseViewportBy={{ bottom: 1200, top: 1200 }}
increaseViewportBy={isInAllView || isInSubscriptionsView || isInModView ? { bottom: 600, top: 600 } : { bottom: 1200, top: 1200 }}
totalCount={rows?.length || 0}
data={rows}
itemContent={(index, row) => <CatalogRow index={index} row={row} />}
+3 -3
View File
@@ -771,7 +771,7 @@ const ModQueueView = ({ boardIdentifier: propBoardIdentifier }: ModQueueViewProp
data={feed}
totalCount={feed.length}
endReached={loadMore}
increaseViewportBy={{ bottom: 1200, top: 1200 }}
increaseViewportBy={{ bottom: 600, top: 600 }}
itemContent={(index, comment) => <ModQueueRow key={comment.cid} comment={comment} isOdd={index % 2 === 0} />}
components={footerComponents}
/>
@@ -799,7 +799,7 @@ const ModQueueView = ({ boardIdentifier: propBoardIdentifier }: ModQueueViewProp
data={feed}
totalCount={feed.length}
endReached={loadMore}
increaseViewportBy={{ bottom: 1200, top: 1200 }}
increaseViewportBy={{ bottom: 600, top: 600 }}
itemContent={(_index, comment) => <ModQueueCard key={comment.cid} comment={comment} />}
components={footerComponents}
/>
@@ -827,7 +827,7 @@ const ModQueueView = ({ boardIdentifier: propBoardIdentifier }: ModQueueViewProp
data={feed}
totalCount={feed.length}
endReached={loadMore}
increaseViewportBy={{ bottom: 1200, top: 1200 }}
increaseViewportBy={{ bottom: 600, top: 600 }}
itemContent={(_index, comment) => <ModQueueFeedPost key={comment.cid} comment={comment} />}
components={footerComponents}
/>