Skip to content

Implement list virtualization for Home feed#17

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-list-virtualization
Draft

Implement list virtualization for Home feed#17
Copilot wants to merge 2 commits intomainfrom
copilot/add-list-virtualization

Conversation

Copy link
Contributor

Copilot AI commented Nov 8, 2025

Home screen rendered all posts synchronously (capped at 500), causing expensive renders on load.

Changes

  • Feed component: Replaced full list rendering with @tanstack/react-virtual (v3.13.12)

    • Virtualizer configured for window-level scrolling with dynamic height measurement
    • Renders only visible items + 5-item overscan buffer
    • Preserves existing scroll position restoration and memoization
  • Manager: Removed 500-post limit from onPostsChanged, getReplies, and getAllReplies

Implementation

const virtualizer = useVirtualizer({
  count: posts.length,
  getScrollElement: () => window.document.documentElement,
  estimateSize: () => 200,
  overscan: 5,
});

const items = virtualizer.getVirtualItems();

// Render only visible items with absolute positioning
items.map((virtualItem) => {
  const post = posts[virtualItem.index];
  return (
    <div
      key={post.id}
      ref={virtualizer.measureElement}
      style={{
        position: "absolute",
        transform: `translateY(${virtualItem.start}px)`,
      }}
    >
      <PostItem post={post} />
    </div>
  );
});

Screenshots

Feed with 100+ posts (scrolled):
Virtualized feed

Constant ~10-15 DOM nodes regardless of total post count.

Original prompt

This section details on the original issue you should resolve

<issue_title>add list virtualization instead of showing only X last posts</issue_title>
<issue_description>currently loading the Home screen is really expensive, all posts are rendered so currently we limit the list to the last 500 posts,
some list virtualization is needed to lazily render items/posts</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: adbenitez <24558636+adbenitez@users.noreply.github.com>
Copilot AI changed the title [WIP] Add list virtualization for home screen posts Implement list virtualization for Home feed Nov 8, 2025
Copilot AI requested a review from adbenitez November 8, 2025 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add list virtualization instead of showing only X last posts

2 participants