Skip to content

Comments

switch to react-virtuoso#479

Merged
MrgSub merged 9 commits intostagingfrom
fix/fix-mail-list-re-rendering
Mar 19, 2025
Merged

switch to react-virtuoso#479
MrgSub merged 9 commits intostagingfrom
fix/fix-mail-list-re-rendering

Conversation

@ahmetskilinc
Copy link
Contributor

@ahmetskilinc ahmetskilinc commented Mar 18, 2025

provides better rendering

Summary by CodeRabbit

  • New Features

    • Enhanced scrolling for emails and drafts using an advanced virtualization approach, ensuring smoother navigation through large lists.
  • Refactor

    • Redesigned the presentation of mail threads and draft items for a more consistent and streamlined interface.
    • Updated interaction behaviors to improve overall user experience.

@vercel
Copy link

vercel bot commented Mar 18, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
0 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 19, 2025 2:22am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 18, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request refactors several mail and draft list components to adopt the Virtuoso library for virtualization. It streamlines imports, simplifies scrolling logic, and reorganizes the component structures—converting the MailList component to a memoized function and modifying the Thread component layout. Additionally, the asynchronous behavior in the MailPage was replaced with synchronous execution, and a new dependency on react-virtuoso was added.

Changes

File(s) Change Summary
apps/mail/components/mail/mail-list.tsx
apps/mail/components/draft/drafts-list.tsx
Refactored list components to use Virtuoso for virtualization; streamlined imports; replaced custom virtualizer logic with a rowRenderer callback; updated scroll references to VirtuosoHandle; adjusted inner component layouts and commented out toast notifications in MailList.
apps/mail/app/(routes)/mail/draft/page.tsx Removed the async keyword from MailPage, converting it from an asynchronous to a synchronous function.
apps/mail/package.json Added a new dependency: "react-virtuoso": "^4.12.5".

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant V as Virtuoso Component
    participant ML as MailList (Memoized)
    participant T as Thread Component

    U->>V: Initiate scroll event
    V->>ML: Call rowRenderer callback
    ML->>T: Render mail item
    T-->>V: Return rendered item
    V-->>U: Display updated mail list
Loading
sequenceDiagram
    participant U as User
    participant V as Virtuoso Component
    participant DL as DraftsList
    participant D as Draft Component

    U->>V: Initiate scroll event
    V->>DL: Call rowRenderer callback
    DL->>D: Render draft item
    D-->>V: Return rendered item
    V-->>U: Display updated draft list
Loading

Possibly related PRs

Suggested reviewers

  • nizzyabi
  • ahmetskilinc

Poem

I'm just a bunny, hopping through code,
Making lists virtual in a brave new mode.
Imports streamlined, scrolls refined,
A refactor so clever, it's one of a kind!
With Virtuoso in hand and code so bright,
I celebrate changes with a joyful delight!
🐇💻 Hop on, team, into the night!

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 690f103 and 9d1aee2.

📒 Files selected for processing (1)
  • apps/mail/components/mail/mail-list.tsx (7 hunks)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ahmetskilinc ahmetskilinc marked this pull request as draft March 18, 2025 22:07
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: 0

🧹 Nitpick comments (4)
apps/mail/components/mail/mail-list.tsx (4)

33-33: Hover-based prefetch delay
Defining HOVER_DELAY is a clear way to manage prefetch timing. You could consider making this configurable if user feedback varies.


246-252: scrollRef and handleScroll logic
Your condition checks prevent redundant loading, which is excellent. Consider removing or replacing the console.log with a more robust logging mechanism for production.

- console.log('Loading more items...');
+ // console.debug('Loading more items...');

265-265: Commented-out toast call
Leaving commented-out code may lead to confusion. Either remove or add a clarifying comment if it's intended for future use.


533-548: rowRenderer callback
Using useCallback is optimal for rerender performance. Defining a proper type instead of @ts-expect-error would solidify type safety.

- // @ts-expect-error
(props) => (
+ (props: { index: number; data: InitialThread }) => (
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 34023ac and 0b5d614.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • apps/mail/components/mail/mail-list.tsx (7 hunks)
  • apps/mail/package.json (1 hunks)
🔇 Additional comments (10)
apps/mail/package.json (1)

100-100: Added "react-virtuoso" dependency
This addition aligns perfectly with the goal of leveraging efficient list virtualization.

apps/mail/components/mail/mail-list.tsx (9)

12-13: Refined import statements
Consolidating type imports from '@/types' and including icon imports from 'lucide-react' is well-organized.


20-21: Utilization of next-intl and ScrollArea
Adopting useFormatter from next-intl and the custom ScrollArea component is a good approach for i18n and structured scrolling.


23-23: Type import from react-virtuoso
Importing VirtuosoHandle helps maintain reliable typings for controlling the virtualized list.


29-29: Introducing Virtuoso
Migrating to the react-virtuoso library is a key part of improving scrolling performance.


131-201: Refactored Thread component structure
Wrapping content in <div className="p-1"> and separating event handlers on a nested <div> provides a more readable layout. Keep an eye on accessibility for any clickable container elements.


221-221: Memoization of MailList
Encapsulating MailList with memo can reduce unnecessary re-renders and improve overall performance.


333-333: New hotkey for marking unread
Double-check for any conflicts with other system/app shortcuts—otherwise, this is a useful addition.


421-450: Global key state management
Attaching and removing key and window blur event listeners is done correctly, including cleanup. This approach effectively handles multi-select mode toggling.


550-573: Implementing Virtuoso in the render flow
This integration neatly handles large lists with infinite scrolling. The code looks clean, and the virtualization logic should be significantly more efficient.

@ahmetskilinc ahmetskilinc marked this pull request as ready for review March 19, 2025 00:17
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: 0

🧹 Nitpick comments (3)
apps/mail/components/draft/drafts-list.tsx (3)

119-123: Remove console.log statement before deployment.

There's a debug console.log statement that should be removed before deploying to production.

 const handleScroll = useCallback(() => {
 	if (isLoading || isValidating || !nextPageToken) return;
-	console.log('Loading more items...');
 	void loadMore();
 }, [isLoading, isValidating, loadMore, nextPageToken]);

361-374: Fix type issue in rowRenderer function.

The rowRenderer function has a TODO comment and a ts-expect-error annotation that should be addressed for proper type safety.

You can fix the typing issue by properly defining the type for the props parameter:

const rowRenderer = useCallback(
-	//TODO: Add proper typing
-	// @ts-expect-error
-	(props) => (
+	(props: { index: number; data: InitialThread }) => (
		<Draft
			onClick={handleMailClick}
			selectMode={selectMode}
			isCompact={isCompact}
			message={props.data}
			{...props}
		/>
	),
	[handleMailClick, selectMode, isCompact],
);

48-97: Consider memoizing the Draft component for better performance.

The Draft component is being rendered for potentially many items in the virtualized list. Memoizing it could prevent unnecessary re-renders and further improve performance.

-const Draft = ({ message, onClick }: ThreadProps) => {
+const Draft = React.memo(({ message, onClick }: ThreadProps) => {
	const [mail] = useMail();
	const [searchValue] = useSearchValue();

	const isMailSelected = message.id === mail.selected;
	const isMailBulkSelected = mail.bulkSelected.includes(message.id);

	return (
		<div className="p-1">
			{/* component content */}
		</div>
	);
-};
+});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0b5d614 and 690f103.

📒 Files selected for processing (7)
  • apps/mail/app/(auth)/login/login-client.tsx (1 hunks)
  • apps/mail/app/(routes)/mail/draft/page.tsx (1 hunks)
  • apps/mail/components/create/create-email.tsx (1 hunks)
  • apps/mail/components/draft/drafts-list.tsx (4 hunks)
  • apps/mail/components/draft/drafts.tsx (1 hunks)
  • apps/mail/components/ui/nav-main.tsx (1 hunks)
  • apps/mail/hooks/use-notes.tsx (2 hunks)
✅ Files skipped from review due to trivial changes (5)
  • apps/mail/components/draft/drafts.tsx
  • apps/mail/app/(auth)/login/login-client.tsx
  • apps/mail/hooks/use-notes.tsx
  • apps/mail/components/ui/nav-main.tsx
  • apps/mail/components/create/create-email.tsx
🔇 Additional comments (5)
apps/mail/app/(routes)/mail/draft/page.tsx (1)

3-3: Good decision to remove the async keyword.

Since this component is only rendering another component and not performing any asynchronous operations, removing the async keyword is appropriate and aligns with React best practices.

apps/mail/components/draft/drafts-list.tsx (4)

6-6: Good addition of react-virtuoso.

Adding the Virtuoso component from react-virtuoso is a good choice for performance optimization when rendering large lists.


117-117: Correct typing update for scrollRef.

Updating the ref type from HTMLDivElement to VirtuosoHandle is necessary for properly interacting with the Virtuoso component's API.


379-387: Good implementation of the Virtuoso component.

The Virtuoso component is correctly set up with the appropriate props for virtualized rendering. This will significantly improve performance when rendering large lists of drafts.


389-397: Good loading indicator implementation.

The loading indicator is well implemented, showing a spinner when more items are being loaded and a placeholder div when not loading.

@MrgSub MrgSub merged commit 865341d into staging Mar 19, 2025
3 of 5 checks passed
This was referenced May 23, 2025
@BlankParticle BlankParticle deleted the fix/fix-mail-list-re-rendering branch May 25, 2025 13:43
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.

2 participants