Skip to content

feat: add shared VirtualList component; migrate DiscussionsList to virtua#39394

Open
srijnabhargav wants to merge 6 commits into
RocketChat:developfrom
srijnabhargav:feat/tanstack-virtual-poc
Open

feat: add shared VirtualList component; migrate DiscussionsList to virtua#39394
srijnabhargav wants to merge 6 commits into
RocketChat:developfrom
srijnabhargav:feat/tanstack-virtual-poc

Conversation

@srijnabhargav
Copy link
Copy Markdown
Contributor

@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 and a new custom virtualized scrollbars component for more efficient list rendering.
  • Refactor

    • Discussions list updated to use the new virtualization and 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
Copy Markdown
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
Copy Markdown

changeset-bot Bot commented Mar 5, 2026

⚠️ No Changeset found

Latest commit: 4ba2638

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
Copy Markdown
Contributor

coderabbitai Bot commented Mar 5, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 28ce7f61-eaeb-42c0-87fa-ceb30629e59d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

Adds a new generic VirtualList component using virtua, introduces CustomVirtuaScrollbars, refactors DiscussionsList to use VirtualList (removing resize-observer and height/width logic, and changing loadMoreItems to a parameterless callback), adds tests for DiscussionsList, and adds the virtua dependency.

Changes

Virtual list & app usage

Layer / File(s) Summary
Data Shape / Types
apps/meteor/client/components/VirtualList/VirtualList.tsx
Defines VirtualListProps<T> requiring T include _id: string, plus items, totalCount, renderItem, optional estimateSize, optional onEndReached.
Core Implementation
apps/meteor/client/components/VirtualList/VirtualList.tsx
Implements VirtualList using virtua VList, tracks virtualizer handle, computes near-bottom using offset/scrollSize/viewportSize, deduplicates end-reached calls with a ${items.length}:${totalCount} key, passes per-row minHeight from estimateSize, renders rows with renderItem.
Barrel Export
apps/meteor/client/components/VirtualList/index.ts
Re-exports the default VirtualList as named VirtualList.

Scrollbars integration

Layer / File(s) Summary
Component API
packages/ui-client/src/components/CustomScrollbars/CustomVirtuaScrollbars.tsx
Adds CustomVirtuaScrollbars component props type and forwardRef signature.
Runtime Wiring
packages/ui-client/src/components/CustomScrollbars/CustomVirtuaScrollbars.tsx
Wraps BaseScrollbars, initializes overlayscrollbars when viewport is present, sets viewport overflow styles from CSS variables, forwards viewport element to external ref, and destroys overlay on cleanup.
Barrel Export
packages/ui-client/src/components/CustomScrollbars/index.ts
Re-exports CustomVirtuaScrollbars default export from ./CustomVirtuaScrollbars.

DiscussionsList refactor & tests

Layer / File(s) Summary
API Change
apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.tsx
Replaces Virtuoso-based virtualization and resize-observer sizing with VirtualList; removes size refs and explicit height/width passing; updates loadMoreItems signature from (start, end) => void to () => void.
Render Wiring
apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.tsx
Uses VirtualList with estimateSize and onEndReached, renders rows via renderItem mapping to DiscussionsListRow.
Tests
apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.spec.tsx
Adds unit tests that mock VList, CustomVirtuaScrollbars, DiscussionsListRow, i18n, and context hooks; asserts loading behavior, error rendering, empty state, and per-item row rendering.

Dependency

Layer / File(s) Summary
Package manifest
apps/meteor/package.json
Adds runtime dependency virtua: ^0.49.0.

Sequence Diagram

sequenceDiagram
    participant DiscussionsList
    participant VirtualList
    participant Virtua as "virtua (VList)"
    participant Scrollbars as "CustomVirtuaScrollbars"

    DiscussionsList->>VirtualList: render(items, totalCount, renderItem, onEndReached)
    VirtualList->>Virtua: initialize virtualizer (count, estimateSize)
    Virtua-->>VirtualList: provide virtual items, totalSize, virtualizer handle
    VirtualList->>Scrollbars: attach scroll element / forward ref
    Scrollbars->>VirtualList: emit scroll events (offset, viewportSize, scrollSize)
    VirtualList->>Virtua: update scroll offset / request visible items
    Virtua-->>VirtualList: visible virtual item indexes
    VirtualList->>DiscussionsList: call renderItem for visible items
    alt near-bottom and items.length < totalCount and key changed
        VirtualList->>DiscussionsList: call onEndReached()
        DiscussionsList->>DiscussionsList: loadMoreItems()
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately summarizes the main changes: adding a shared VirtualList component and migrating DiscussionsList to use virtua (a virtual list library), which aligns with the core changeset across multiple files.

✏️ 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
Copy Markdown
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
Copy Markdown
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

Comment thread apps/meteor/client/components/VirtualList/VirtualList.tsx Outdated
@srijnabhargav
Copy link
Copy Markdown
Contributor 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
@coderabbitai coderabbitai Bot removed the type: feature Pull requests that introduces new feature label May 8, 2026
Copy link
Copy Markdown
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: 2

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

62-67: ⚡ Quick win

The @rocket.chat/ui-contexts mock replaces the entire module without spreading jest.requireActual.

If DiscussionsList (or any component in its tree) imports anything else from @rocket.chat/ui-contexts beyond the four hooks listed here (useSetting, useLayoutSizes, useLayoutContextualBarPosition, useRoomToolbox), those imports will silently be undefined at runtime in the test, potentially causing cryptic failures.

♻️ Proposed fix
 jest.mock('@rocket.chat/ui-contexts', () => ({
+	...jest.requireActual('@rocket.chat/ui-contexts'),
 	useSetting: () => false,
 	useLayoutSizes: () => ({ contextualBar: 'wide' }),
 	useLayoutContextualBarPosition: () => 'side',
 	useRoomToolbox: () => ({ closeTab: jest.fn() }),
 }));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.spec.tsx`
around lines 62 - 67, The current jest.mock for '@rocket.chat/ui-contexts'
overwrites the entire module and may make other imports undefined; update the
mock to spread the real module using const actual =
jest.requireActual('@rocket.chat/ui-contexts') and return { ...actual,
useSetting: () => false, useLayoutSizes: () => ({ contextualBar: 'wide' }),
useLayoutContextualBarPosition: () => 'side', useRoomToolbox: () => ({ closeTab:
jest.fn() }) } so only the four hooks (useSetting, useLayoutSizes,
useLayoutContextualBarPosition, useRoomToolbox) are overridden while preserving
all other exports.

8-13: 💤 Low value

Code comments in implementation files violate the project guideline.

Lines 8–9 and 12 contain block comments explaining the mock rationale. As per coding guidelines, code comments should be avoided in *.{ts,tsx,js} files.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.spec.tsx`
around lines 8 - 13, Remove the inline block comments surrounding the two
jest.mock calls (the comments on DiscussionsListRow and goToRoomById) and leave
only the mock declarations so the test file contains no implementation comments;
keep the existing mocks for DiscussionsListRow (the JSX sentinel) and the
goToRoomById mock (jest.fn()), and if you need to preserve the rationale, move
it into the test description or the PR/commit message instead of keeping
comments in the .tsx file.
apps/meteor/client/components/VirtualList/VirtualList.tsx (2)

67-71: ⚡ Quick win

Memoize the items.map(...) element array to preserve VList's internal optimizations.

In complex usage, especially if you re-render frequently the parent of virtual scroller or the children are tons of items, children element creation can be a performance bottleneck. Creating React elements is fast enough but not free, and new React element instances break some of memoization inside virtual scroller. One solution is memoization with useMemo to reduce computation and keep the elements' instances the same. If you want to pass state from parent to the items, using context instead of props may be better because it doesn't break the memoization.

♻️ Proposed refactor
+import { useCallback, useEffect, useMemo, useRef } from 'react';
 
+	const rowElements = useMemo(
+		() =>
+			items.map((item, index) => (
+				<div key={item._id} style={{ minHeight: estimateSize(index) }}>
+					{renderItem(item, index)}
+				</div>
+			)),
+		[items, estimateSize, renderItem],
+	);
 
 	return (
 		<CustomVirtuaScrollbars>
 			<VList ref={virtualizerRef} style={{ height: '100%' }} onScroll={handleScroll}>
-				{items.map((item, index) => (
-					<div key={item._id} style={{ minHeight: estimateSize(index) }}>
-						{renderItem(item, index)}
-					</div>
-				))}
+				{rowElements}
 			</VList>
 		</CustomVirtuaScrollbars>
 	);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/meteor/client/components/VirtualList/VirtualList.tsx` around lines 67 -
71, The items.map(...) JSX should be memoized to avoid recreating child elements
on every render; inside the VirtualList component, create a useMemo (e.g., const
renderedItems = useMemo(() => items.map((item, index) => <div key={item._id}
style={{minHeight: estimateSize(index)}}>{renderItem(item, index)}</div>),
[items, estimateSize, renderItem]) and then render {renderedItems} instead of
calling items.map inline; this preserves element instances for the virtual
scroller and references the unique symbols items, estimateSize, renderItem, and
the VirtualList component.

9-15: 💤 Low value

estimateSize prop name is misleading — it acts as a CSS minHeight, not a Virtua size estimator.

Virtua's VList has no estimateSize prop (unlike TanStack Virtual). The current code applies the return value as style={{ minHeight: estimateSize(index) }} on a wrapper div. Calling the prop estimateSize borrows TanStack Virtual terminology and will confuse readers into expecting Virtua-style measurement behavior. Consider itemMinHeight or minItemSize to accurately convey its role.

♻️ Proposed rename
-	estimateSize?: (index: number) => number;
+	minItemSize?: (index: number) => number;
 
 function VirtualList<T extends { _id: string }>({
 	items,
 	totalCount,
 	renderItem,
-	estimateSize = () => 120,
+	minItemSize = () => 120,
 	onEndReached,
 }: VirtualListProps<T>) {
 
 			<div key={item._id} style={{ minHeight: estimateSize(index) }}>
+			<div key={item._id} style={{ minHeight: minItemSize(index) }}>
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/meteor/client/components/VirtualList/VirtualList.tsx` around lines 9 -
15, Rename the misleading prop estimateSize in the VirtualList component to a
clearer name like itemMinHeight (or minItemSize) across the VirtualListProps
type and the VirtualList component implementation; update the prop signature in
type VirtualListProps<T extends { _id: string }>, change any parameter and
destructuring in the VirtualList function that references estimateSize, and
replace uses where you set style={{ minHeight: estimateSize(index) }} to
style={{ minHeight: itemMinHeight(index) }} (and adjust any default/optional
handling). Also update all external call sites and tests that pass estimateSize
to use the new name to keep the API consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/meteor/client/components/VirtualList/VirtualList.tsx`:
- Around line 32-62: The list never calls onEndReached when initial items don't
fill the viewport because handleScroll is only invoked on user scroll; add a
mount/visibility-time check using the virtualizer's onRangeChange callback (or
equivalent VList.onRangeChange) to run the same end-of-list logic used in
handleScroll. Reuse the same guards and key deduplication (lastEndReachKeyRef,
items.length, totalCount, NEAR_BOTTOM_THRESHOLD, virtualizerRef,
onEndReachedRef) when implementing the onRangeChange handler so it triggers
loadMore on mount if the rendered range is already near the bottom or the list
is underfilled; ensure you still keep the viewportSize <= 0 startup guard and
avoid duplicating behavior by delegating to the existing handleScroll logic or
extracting the common check into a helper invoked by both handlers.

In
`@packages/ui-client/src/components/CustomScrollbars/CustomVirtuaScrollbars.tsx`:
- Around line 14-29: The initialized event handler passed into
useOverlayScrollbars captures the incoming prop ref in a stale closure; update
the code so the handler always forwards the current ref instead of the one from
first render—e.g., create a stable mutable container (like latestRefRef =
useRef(ref)), update latestRefRef.current in a useEffect when ref changes, and
have the events.initialized callback read latestRefRef.current before forwarding
the viewport (the handler that calls ref(viewport) / ref.current = viewport and
accesses osInstance.elements()). This preserves the existing behavior but
ensures function refs passed from parents are invoked with the latest reference.

---

Nitpick comments:
In `@apps/meteor/client/components/VirtualList/VirtualList.tsx`:
- Around line 67-71: The items.map(...) JSX should be memoized to avoid
recreating child elements on every render; inside the VirtualList component,
create a useMemo (e.g., const renderedItems = useMemo(() => items.map((item,
index) => <div key={item._id} style={{minHeight:
estimateSize(index)}}>{renderItem(item, index)}</div>), [items, estimateSize,
renderItem]) and then render {renderedItems} instead of calling items.map
inline; this preserves element instances for the virtual scroller and references
the unique symbols items, estimateSize, renderItem, and the VirtualList
component.
- Around line 9-15: Rename the misleading prop estimateSize in the VirtualList
component to a clearer name like itemMinHeight (or minItemSize) across the
VirtualListProps type and the VirtualList component implementation; update the
prop signature in type VirtualListProps<T extends { _id: string }>, change any
parameter and destructuring in the VirtualList function that references
estimateSize, and replace uses where you set style={{ minHeight:
estimateSize(index) }} to style={{ minHeight: itemMinHeight(index) }} (and
adjust any default/optional handling). Also update all external call sites and
tests that pass estimateSize to use the new name to keep the API consistent.

In
`@apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.spec.tsx`:
- Around line 62-67: The current jest.mock for '@rocket.chat/ui-contexts'
overwrites the entire module and may make other imports undefined; update the
mock to spread the real module using const actual =
jest.requireActual('@rocket.chat/ui-contexts') and return { ...actual,
useSetting: () => false, useLayoutSizes: () => ({ contextualBar: 'wide' }),
useLayoutContextualBarPosition: () => 'side', useRoomToolbox: () => ({ closeTab:
jest.fn() }) } so only the four hooks (useSetting, useLayoutSizes,
useLayoutContextualBarPosition, useRoomToolbox) are overridden while preserving
all other exports.
- Around line 8-13: Remove the inline block comments surrounding the two
jest.mock calls (the comments on DiscussionsListRow and goToRoomById) and leave
only the mock declarations so the test file contains no implementation comments;
keep the existing mocks for DiscussionsListRow (the JSX sentinel) and the
goToRoomById mock (jest.fn()), and if you need to preserve the rationale, move
it into the test description or the PR/commit message instead of keeping
comments in the .tsx file.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6848c230-ac11-4c11-a971-acc595010368

📥 Commits

Reviewing files that changed from the base of the PR and between e25071e and 350c88b.

⛔ 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/views/room/contextualBar/Discussions/DiscussionsList.spec.tsx
  • apps/meteor/package.json
  • packages/ui-client/src/components/CustomScrollbars/CustomVirtuaScrollbars.tsx
  • packages/ui-client/src/components/CustomScrollbars/index.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/ui-client/src/components/CustomScrollbars/index.ts
📜 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:

  • packages/ui-client/src/components/CustomScrollbars/CustomVirtuaScrollbars.tsx
  • apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.spec.tsx
  • apps/meteor/client/components/VirtualList/VirtualList.tsx
🧠 Learnings (3)
📚 Learning: 2026-03-27T14:52:56.865Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 39892
File: apps/meteor/client/views/room/contextualBar/Threads/Thread.tsx:150-155
Timestamp: 2026-03-27T14:52:56.865Z
Learning: In Rocket.Chat, there are two different `ModalBackdrop` components with different prop APIs. During review, confirm the import source: (1) `rocket.chat/fuselage` `ModalBackdrop` uses `ModalBackdropProps` based on `BoxProps` (so it supports `onClick` and other Box/DOM props) and does not have an `onDismiss` prop; (2) `rocket.chat/ui-client` `ModalBackdrop` uses a narrower props interface like `{ children?: ReactNode; onDismiss?: () => void }` and handles Escape keypress and outside mouse-up, and it does not forward arbitrary DOM props such as `onClick`. Flag mismatched props (e.g., `onDismiss` passed to the fuselage component or `onClick` passed to the ui-client component) and ensure the usage matches the correct component being imported.

Applied to files:

  • packages/ui-client/src/components/CustomScrollbars/CustomVirtuaScrollbars.tsx
  • apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.spec.tsx
  • apps/meteor/client/components/VirtualList/VirtualList.tsx
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • packages/ui-client/src/components/CustomScrollbars/CustomVirtuaScrollbars.tsx
  • apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.spec.tsx
  • apps/meteor/client/components/VirtualList/VirtualList.tsx
📚 Learning: 2026-03-06T18:10:15.268Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 39397
File: packages/gazzodown/src/code/CodeBlock.spec.tsx:47-68
Timestamp: 2026-03-06T18:10:15.268Z
Learning: In tests (especially those using testing-library/dom/jsdom) for Rocket.Chat components, the HTML <code> element has an implicit ARIA role of 'code'. Therefore, screen.getByRole('code') or screen.findByRole('code') will locate <code> elements even without a role attribute. Do not flag findByRole('code') as invalid in reviews; prefer using the implicit role instead of adding role="code" unless necessary for accessibility.

Applied to files:

  • apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.spec.tsx
🔇 Additional comments (2)
apps/meteor/package.json (1)

278-278: ⚡ Quick win

react-virtuoso is still needed — it remains widely used throughout the codebase (27+ files including ThreadList, RoomMembers, RoomFiles, MessageSearch, VideoConfList, OmniChannel components, and more). While DiscussionsList may have been migrated to virtua, this does not eliminate the dependency. The ^0.49.0 version range is appropriate and already covers patch version 0.49.1.

			> Likely an incorrect or invalid review comment.
packages/ui-client/src/components/CustomScrollbars/CustomVirtuaScrollbars.tsx (1)

31-44: ⚡ Quick win

BaseScrollbars does not wrap children in intermediate containers.

BaseScrollbars is a simple Box wrapper that directly spreads props (including children) to the underlying Box element. There are no padding divs, flex wrappers, or other intermediate elements between the Box root and its rendered children. Therefore, root.firstElementChild correctly points to the first child element passed to CustomVirtuaScrollbars, not to an intermediate wrapper.

If a potential issue exists, it would arise from callers of CustomVirtuaScrollbars wrapping their VList in intermediate containers before passing it as children—but that is a consumer responsibility, not a problem with BaseScrollbars itself.

			> Likely an incorrect or invalid review comment.

Comment thread apps/meteor/client/components/VirtualList/VirtualList.tsx Outdated
Comment thread packages/ui-client/src/components/CustomScrollbars/CustomVirtuaScrollbars.tsx Outdated
@srijnabhargav srijnabhargav changed the title feat: add shared VirtualList component; migrate DiscussionsList from Virtuoso to TanStack Virtual feat: add shared VirtualList component; migrate DiscussionsList to virtua May 9, 2026
Copy link
Copy Markdown
Member

@MartinSchoeler MartinSchoeler left a comment

Choose a reason for hiding this comment

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

Check the style linting, as the CI did flag some errors.

Comment thread apps/meteor/client/components/VirtualList/VirtualList.tsx Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

❌ Patch coverage is 95.54140% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.84%. Comparing base (741b87f) to head (4ba2638).
⚠️ Report is 3 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #39394      +/-   ##
===========================================
+ Coverage    69.73%   69.84%   +0.11%     
===========================================
  Files         3326     3330       +4     
  Lines       123056   123269     +213     
  Branches     21962    22016      +54     
===========================================
+ Hits         85816    86101     +285     
+ Misses       33880    33806      -74     
- Partials      3360     3362       +2     
Flag Coverage Δ
e2e 59.39% <ø> (+0.07%) ⬆️
e2e-api 46.08% <ø> (-0.02%) ⬇️
unit 70.59% <95.54%> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@srijnabhargav srijnabhargav marked this pull request as draft May 13, 2026 12:23
@srijnabhargav srijnabhargav marked this pull request as ready for review May 15, 2026 05:48
@srijnabhargav srijnabhargav marked this pull request as draft May 19, 2026 22:25
@srijnabhargav srijnabhargav marked this pull request as ready for review May 23, 2026 09:49
Copy link
Copy Markdown
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.

1 issue found across 10 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread apps/meteor/client/components/VirtualList/VirtualList.tsx Outdated
@srijnabhargav srijnabhargav marked this pull request as draft May 25, 2026 19:52
@srijnabhargav srijnabhargav marked this pull request as ready for review May 26, 2026 16:45
@srijnabhargav srijnabhargav requested a review from a team as a code owner May 26, 2026 16:45
Copy link
Copy Markdown
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.

1 issue found across 10 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread apps/meteor/client/components/VirtualList/VirtualList.tsx Outdated
@srijnabhargav srijnabhargav marked this pull request as draft May 27, 2026 17:59
@cubic-dev-ai
Copy link
Copy Markdown
Contributor

cubic-dev-ai Bot commented May 27, 2026

You're iterating quickly on this pull request. To help protect your rate limits, cubic has paused automatic reviews on new pushes for now—when you're ready for another review, comment @cubic-dev-ai review.

@srijnabhargav srijnabhargav marked this pull request as ready for review May 27, 2026 18:26
Copy link
Copy Markdown
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.

2 issues found across 10 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.tsx Outdated
Comment thread apps/meteor/client/components/VirtualList/VirtualList.tsx Outdated
@srijnabhargav srijnabhargav marked this pull request as draft May 27, 2026 19:17
Introduces a generic VirtualList component backed by the virtua Virtualizer.
Supports end-reach callbacks (with async lock), configurable overscan, and a
semantic ul/li structure via VirtuaListContainer. Pairs with the existing
CustomVirtuaScrollbars from @rocket.chat/ui-client.
Replaces the Virtuoso + VirtualizedScrollbars + useResizeObserver setup with
the new VirtualList component. The loadMoreItems signature simplifies from
(start, end) to () => void, deferring pagination logic to the data layer.
- New VirtualList.spec.tsx covers end-reach, overscan, and scroll behaviour
  using a mocked Virtualizer handle
- DiscussionsList.spec.tsx updated for the virtua-backed VirtualList (new
  snapshot generated)
- MessageList.spec.tsx: replace require('react') with jest.requireActual to
  silence @typescript-eslint/no-require-imports
@srijnabhargav srijnabhargav force-pushed the feat/tanstack-virtual-poc branch from 571a03f to 4f26f66 Compare May 27, 2026 19:52
@srijnabhargav srijnabhargav marked this pull request as ready for review May 28, 2026 12:09
Copy link
Copy Markdown
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.

1 issue found across 9 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@srijnabhargav
Copy link
Copy Markdown
Contributor Author

@cubic-dev-ai review

@cubic-dev-ai
Copy link
Copy Markdown
Contributor

cubic-dev-ai Bot commented May 28, 2026

@cubic-dev-ai review

@srijnabhargav I have started the AI code review. It will take a few minutes to complete.

Copy link
Copy Markdown
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.

0 issues found across 1 file (changes from recent commits).

Re-trigger cubic

Copy link
Copy Markdown
Member

@MartinSchoeler MartinSchoeler left a comment

Choose a reason for hiding this comment

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

Left some comments and suggestions

Comment thread apps/meteor/client/components/VirtualList/VirtualList.tsx Outdated
Comment thread apps/meteor/client/components/VirtualList/VirtualList.tsx Outdated
Comment thread apps/meteor/client/components/VirtualList/VirtualList.tsx Outdated
Comment thread apps/meteor/client/components/VirtualList/VirtualList.tsx Outdated
Comment thread apps/meteor/client/components/VirtualList/VirtualList.tsx
Comment thread apps/meteor/client/components/VirtualList/VirtualList.tsx Outdated
Comment thread apps/meteor/client/components/VirtualList/VirtualList.tsx Outdated
Comment thread apps/meteor/client/components/VirtualList/VirtualList.tsx Outdated
Comment thread apps/meteor/client/components/VirtualList/VirtualList.tsx Outdated
Comment thread apps/meteor/client/views/room/contextualBar/Discussions/DiscussionsList.tsx Outdated
@srijnabhargav
Copy link
Copy Markdown
Contributor Author

Addressed all review comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community valid A valid contribution where maintainers will review based on priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants