Skip to content

feat: add shared VirtualList component; migrate DiscussionsList from Virtuoso to TanStack Virtual#39394

Open
srijnabhargav wants to merge 4 commits intoRocketChat:developfrom
srijnabhargav:feat/tanstack-virtual-poc
Open

feat: add shared VirtualList component; migrate DiscussionsList from Virtuoso to TanStack Virtual#39394
srijnabhargav wants to merge 4 commits intoRocketChat:developfrom
srijnabhargav:feat/tanstack-virtual-poc

Conversation

@srijnabhargav
Copy link

@srijnabhargav srijnabhargav commented Mar 5, 2026

Proposed changes (including videos or screenshots)

This is a POC for migrating the codebase from react-virtuoso to @tanstack/react-virtual. The goal, as discussed in the channel, is to replace the scattered Virtuoso + VirtualizedScrollbars + useResizeObserver pattern with a single shared headless component.

What's in this PR

New VirtualList component (apps/meteor/client/components/VirtualList/)
A generic VirtualList<T> built on useVirtualizer from @tanstack/react-virtual.
It wraps CustomScrollbars, handles the absolute-positioning pattern, dynamic row measurement via measureElement, and infinite scroll via onEndReached.

It exposes the following options directly from the TanStack Virtual API:

  • estimateSize
  • overscan
  • gap
  • paddingStart
  • paddingEnd

DiscussionsList migrated
Chosen as the first target because it is a pure presentational component with a clean, representative pattern (search + infinite scroll) without the additional complexity of real-time updates or grouped views.

Changes:

  • Removed Virtuoso, VirtualizedScrollbars, and useResizeObserver
  • Simplified the loadMoreItems prop type from:
    (start: number, end: number) => void

to:
() => void

since the parent component already passes it this way.

Tests added for DiscussionsList

Added 4 unit tests covering:

  • loading state
  • error state
  • empty state
  • items rendering

Demo - UI looks unchanged! No Regression

Screen.Recording.2026-03-06.at.12.39.44.AM.mov

Issue(s)

Part of the TanStack Virtual migration discussed in the GSoC channel.

Summary by CodeRabbit

  • New Features

    • Added a VirtualList component for efficient, virtualized list rendering with on-end callbacks.
  • Refactor

    • Updated discussions list API: the loadMoreItems prop is now parameterless.
  • Tests

    • Added unit tests covering loading, error, empty, and list rendering states for discussions.
  • Chores

    • Updated project dependencies.

@srijnabhargav srijnabhargav requested a review from a team as a code owner March 5, 2026 19:44
@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Mar 5, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Mar 5, 2026

⚠️ No Changeset found

Latest commit: e25071e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8ffe7265-d14e-452a-abf3-574e7d9a6340

📥 Commits

Reviewing files that changed from the base of the PR and between 003d066 and e25071e.

📒 Files selected for processing (1)
  • apps/meteor/client/components/VirtualList/VirtualList.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/meteor/client/components/VirtualList/VirtualList.tsx
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: cubic · AI code reviewer

Walkthrough

Adds a new generic VirtualList component using @tanstack/react-virtual; refactors DiscussionsList to use VirtualList (removes resize observer and height/width logic, and changes loadMoreItems to a parameterless callback); adds unit tests for DiscussionsList and adds the dependency.

Changes

Cohort / File(s) Summary
VirtualList Component
apps/meteor/client/components/VirtualList/VirtualList.tsx, apps/meteor/client/components/VirtualList/index.ts
New generic VirtualList implemented with useVirtualizer, configurable estimateSize/overscan/gap/padding, exposes onEndReached for infinite loading; index re-exports it as VirtualList.
DiscussionsList Refactor
apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.tsx
Replaced Virtuoso-based virtualization and resize-observer sizing with the new VirtualList; removed size refs, simplified rendering, and changed loadMoreItems signature from (start, end) => void to () => void.
DiscussionsList Tests
apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.spec.tsx
Added test suite that mocks virtualization, scrollbars, i18n, and context; covers loading, error, empty, and item rendering behaviors.
Dependencies
apps/meteor/package.json
Added dependency @tanstack/react-virtual (~3.13.19).

Sequence Diagram

sequenceDiagram
    participant DiscussionsList
    participant VirtualList
    participant Virtualizer as "@tanstack/react-virtual"
    participant ScrollContainer as CustomScrollbars

    DiscussionsList->>VirtualList: render(items, totalCount, renderItem, onEndReached)
    VirtualList->>Virtualizer: init useVirtualizer(count, estimateSize, overscan)
    Virtualizer->>VirtualList: provide virtual items & totalSize
    VirtualList->>ScrollContainer: attach/observe scroll element
    ScrollContainer->>VirtualList: scroll events
    VirtualList->>Virtualizer: update scroll offset / measure
    VirtualList->>DiscussionsList: invoke renderItem for visible virtual items
    alt last virtual index >= loaded items and totalCount > loaded
        VirtualList->>DiscussionsList: call onEndReached()
        DiscussionsList->>DiscussionsList: loadMoreItems()
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat: add shared VirtualList component; migrate DiscussionsList from Virtuoso to TanStack Virtual' directly matches the main changes: introducing a new VirtualList component and migrating DiscussionsList to use it, clearly summarizing the primary objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai bot added the type: feature Pull requests that introduces new feature label Mar 5, 2026
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 6 files

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.spec.tsx (1)

80-106: Add one regression test for pagination callback behavior.

Please add coverage that loadMoreItems is triggered when end is reached and suppressed when loading is true, since this is part of the migration’s critical behavior.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.spec.tsx`
around lines 80 - 106, Tests for DiscussionsList lack coverage for pagination
callback behavior; add a regression test that renders <DiscussionsList> with a
mock loadMoreItems function and asserts that calling the component's end-reached
trigger (e.g., simulate the virtualized list reaching the end or invoke the
prop/handler that the component uses to detect end) calls loadMoreItems once
when loading is false, and does not call it when loading is true. Use the
DiscussionsList component, the loadMoreItems prop, and the loading prop to
create two cases: one where loading=false and you assert the mock was called
after simulating end reached, and one where loading=true and you assert the mock
was not called.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/meteor/client/components/VirtualList/VirtualList.tsx`:
- Around line 44-48: The effect currently calls onEndReached whenever the
onEndReached reference changes even if lastVirtualItemIndex, items.length, and
totalCount are unchanged; fix by tracking the items.length value that last
triggered onEndReached with a ref (e.g., lastTriggeredItemsLengthRef) inside the
component, and in the useEffect (where lastVirtualItemIndex, items.length,
totalCount, onEndReached are dependencies) only invoke onEndReached when the
conditions match AND lastTriggeredItemsLengthRef.current !== items.length; after
calling, set lastTriggeredItemsLengthRef.current = items.length, and reset the
ref (set to undefined or 0) when items.length decreases or when totalCount
changes if you want to allow re-triggering.

---

Nitpick comments:
In
`@apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.spec.tsx`:
- Around line 80-106: Tests for DiscussionsList lack coverage for pagination
callback behavior; add a regression test that renders <DiscussionsList> with a
mock loadMoreItems function and asserts that calling the component's end-reached
trigger (e.g., simulate the virtualized list reaching the end or invoke the
prop/handler that the component uses to detect end) calls loadMoreItems once
when loading is false, and does not call it when loading is true. Use the
DiscussionsList component, the loadMoreItems prop, and the loading prop to
create two cases: one where loading=false and you assert the mock was called
after simulating end reached, and one where loading=true and you assert the mock
was not called.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5c29b315-f7cd-40c5-b784-2aa068136b9a

📥 Commits

Reviewing files that changed from the base of the PR and between d08306b and 003d066.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (5)
  • apps/meteor/client/components/VirtualList/VirtualList.tsx
  • apps/meteor/client/components/VirtualList/index.ts
  • apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.spec.tsx
  • apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.tsx
  • apps/meteor/package.json
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: cubic · AI code reviewer
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.tsx
  • apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.spec.tsx
  • apps/meteor/client/components/VirtualList/VirtualList.tsx
  • apps/meteor/client/components/VirtualList/index.ts
🧠 Learnings (14)
📚 Learning: 2026-02-25T20:10:16.987Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38913
File: packages/ddp-client/src/legacy/types/SDKLegacy.ts:34-34
Timestamp: 2026-02-25T20:10:16.987Z
Learning: In the RocketChat/Rocket.Chat monorepo, packages/ddp-client and apps/meteor do not use TypeScript project references. Module augmentations in apps/meteor (e.g., declare module 'rocket.chat/rest-typings') are not visible when compiling packages/ddp-client in isolation, which is why legacy SDK methods that depend on OperationResult types for OpenAPI-migrated endpoints must remain commented out.

Applied to files:

  • apps/meteor/package.json
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Utilize Playwright fixtures (`test`, `page`, `expect`) for consistency in test files

Applied to files:

  • apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.spec.tsx
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Group related tests in the same file

Applied to files:

  • apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.spec.tsx
📚 Learning: 2025-12-10T21:00:54.909Z
Learnt from: KevLehman
Repo: RocketChat/Rocket.Chat PR: 37091
File: ee/packages/abac/jest.config.ts:4-7
Timestamp: 2025-12-10T21:00:54.909Z
Learning: Rocket.Chat monorepo: Jest testMatch pattern '<rootDir>/src/**/*.spec.(ts|js|mjs)' is valid in this repo and used across multiple packages (e.g., packages/tools, ee/packages/omnichannel-services). Do not flag it as invalid in future reviews.

Applied to files:

  • apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.spec.tsx
📚 Learning: 2026-02-24T19:36:55.089Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 38493
File: apps/meteor/tests/e2e/page-objects/fragments/home-content.ts:60-82
Timestamp: 2026-02-24T19:36:55.089Z
Learning: In RocketChat/Rocket.Chat e2e tests (apps/meteor/tests/e2e/page-objects/fragments/home-content.ts), thread message preview listitems do not have aria-roledescription="message", so lastThreadMessagePreview locator cannot be scoped to messageListItems (which filters for aria-roledescription="message"). It should remain scoped to page.getByRole('listitem') or mainMessageList.getByRole('listitem').

Applied to files:

  • apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.spec.tsx
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Maintain test isolation between test cases in Playwright tests

Applied to files:

  • apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.spec.tsx
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Ensure tests run reliably in parallel without shared state conflicts

Applied to files:

  • apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.spec.tsx
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : All test files must be created in `apps/meteor/tests/e2e/` directory

Applied to files:

  • apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.spec.tsx
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to **/*.spec.ts : Use descriptive test names that clearly communicate expected behavior in Playwright tests

Applied to files:

  • apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.spec.tsx
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Use `expect` matchers for assertions (`toEqual`, `toContain`, `toBeTruthy`, `toHaveLength`, etc.) instead of `assert` statements in Playwright tests

Applied to files:

  • apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.spec.tsx
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Use `test.step()` for complex test scenarios to improve organization in Playwright tests

Applied to files:

  • apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.spec.tsx
📚 Learning: 2026-02-10T16:32:42.586Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38528
File: apps/meteor/client/startup/roles.ts:14-14
Timestamp: 2026-02-10T16:32:42.586Z
Learning: In Rocket.Chat's Meteor client code, DDP streams use EJSON and Date fields arrive as Date objects; do not manually construct new Date() in stream handlers (for example, in sdk.stream()). Only REST API responses return plain JSON where dates are strings, so implement explicit conversion there if needed. Apply this guidance to all TypeScript files under apps/meteor/client to ensure consistent date handling in DDP streams and REST responses.

Applied to files:

  • apps/meteor/client/components/VirtualList/index.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/client/components/VirtualList/index.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/client/components/VirtualList/index.ts
🔇 Additional comments (3)
apps/meteor/package.json (1)

160-160: Reviewed this dependency addition; no actionable issue in this segment.

apps/meteor/client/components/VirtualList/index.ts (1)

1-1: Barrel export looks correct.

This cleanly exposes the shared VirtualList entrypoint for consumers.

apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.tsx (1)

26-26: Migration wiring is consistent.

The loadMoreItems: () => void contract and VirtualList integration are aligned with the new shared virtual list API.

Also applies to: 86-94

@srijnabhargav
Copy link
Author

@KevLehman @MartinSchoeler Could you please review and let me know if any changes are needed?

@KevLehman KevLehman added the valid A valid contribution where maintainers will review based on priority label Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feature Pull requests that introduces new feature valid A valid contribution where maintainers will review based on priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants