refactor: perf improvements to opening emails, tanstack query caching…#1694
refactor: perf improvements to opening emails, tanstack query caching…#1694MrgSub merged 2 commits intoMail-0:stagingfrom
Conversation
… improvements, callbacks where needed in optimistic actions hook, some formatting
WalkthroughThis update refactors several mail-related components and hooks. It removes unnecessary Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant MailList
participant State
participant OptimisticActions
User->>MailList: Clicks on mail thread
MailList->>State: setThreadId / setDraftId (sync, no await)
MailList->>OptimisticActions: (if needed) optimisticMarkAsRead (via useCallback)
OptimisticActions->>State: setMail (functional update)
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
apps/mail/components/mail/mail-list.tsx(3 hunks)apps/mail/components/mail/thread-display.tsx(4 hunks)apps/mail/hooks/use-notes.tsx(1 hunks)apps/mail/hooks/use-optimistic-actions.ts(3 hunks)apps/mail/hooks/use-summary.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: retrogtx
PR: Mail-0/Zero#1328
File: apps/mail/lib/hotkeys/mail-list-hotkeys.tsx:202-209
Timestamp: 2025-06-18T17:26:50.918Z
Learning: In apps/mail/lib/hotkeys/mail-list-hotkeys.tsx, the switchCategoryByIndex function using hardcoded indices for category hotkeys does not break when users reorder categories, contrary to the theoretical index-shifting issue. The actual implementation has constraints or mechanisms that prevent hotkey targeting issues.
apps/mail/components/mail/mail-list.tsx (4)
Learnt from: retrogtx
PR: Mail-0/Zero#1328
File: apps/mail/lib/hotkeys/mail-list-hotkeys.tsx:202-209
Timestamp: 2025-06-18T17:26:50.918Z
Learning: In apps/mail/lib/hotkeys/mail-list-hotkeys.tsx, the switchCategoryByIndex function using hardcoded indices for category hotkeys does not break when users reorder categories, contrary to the theoretical index-shifting issue. The actual implementation has constraints or mechanisms that prevent hotkey targeting issues.
Learnt from: retrogtx
PR: Mail-0/Zero#1468
File: apps/server/src/trpc/routes/mail.ts:331-331
Timestamp: 2025-06-28T03:56:09.376Z
Learning: In apps/server/src/trpc/routes/mail.ts, the user indicated they are not using ISO format for the scheduleAt parameter, despite the frontend code showing toISOString() usage in the ScheduleSendPicker component.
Learnt from: retrogtx
PR: Mail-0/Zero#1468
File: apps/server/src/trpc/routes/mail.ts:386-391
Timestamp: 2025-06-27T04:59:29.731Z
Learning: In apps/server/src/trpc/routes/mail.ts, the attachment processing logic conditionally handles mixed attachment types - it preserves existing File-like objects with arrayBuffer methods while only converting serialized attachments that need processing through toAttachmentFiles.
Learnt from: danteissaias
PR: Mail-0/Zero#618
File: apps/mail/components/mail/mail-iframe.tsx:12-12
Timestamp: 2025-04-07T20:46:11.697Z
Learning: In the Mail-0/Zero application, sender emails are guaranteed to be non-empty when passed to components that handle them, making additional empty string validation unnecessary.
apps/mail/components/mail/thread-display.tsx (6)
Learnt from: retrogtx
PR: Mail-0/Zero#1328
File: apps/mail/lib/hotkeys/mail-list-hotkeys.tsx:202-209
Timestamp: 2025-06-18T17:26:50.918Z
Learning: In apps/mail/lib/hotkeys/mail-list-hotkeys.tsx, the switchCategoryByIndex function using hardcoded indices for category hotkeys does not break when users reorder categories, contrary to the theoretical index-shifting issue. The actual implementation has constraints or mechanisms that prevent hotkey targeting issues.
Learnt from: retrogtx
PR: Mail-0/Zero#1468
File: apps/server/src/trpc/routes/mail.ts:386-391
Timestamp: 2025-06-27T04:59:29.731Z
Learning: In apps/server/src/trpc/routes/mail.ts, the attachment processing logic conditionally handles mixed attachment types - it preserves existing File-like objects with arrayBuffer methods while only converting serialized attachments that need processing through toAttachmentFiles.
Learnt from: snehendu098
PR: Mail-0/Zero#1323
File: apps/mail/lib/themes/theme-utils.ts:318-318
Timestamp: 2025-06-24T06:22:58.753Z
Learning: In the Mail-0/Zero theme system (apps/mail/lib/themes/theme-utils.ts), when color themes are being applied, all color values come in HSL format, so there's no need for additional format validation when converting colors with hslToHex().
Learnt from: danteissaias
PR: Mail-0/Zero#618
File: apps/mail/components/mail/mail-iframe.tsx:12-12
Timestamp: 2025-04-07T20:46:11.697Z
Learning: In the Mail-0/Zero application, sender emails are guaranteed to be non-empty when passed to components that handle them, making additional empty string validation unnecessary.
Learnt from: retrogtx
PR: Mail-0/Zero#1468
File: apps/server/src/trpc/routes/mail.ts:331-331
Timestamp: 2025-06-28T03:56:09.376Z
Learning: In apps/server/src/trpc/routes/mail.ts, the user indicated they are not using ISO format for the scheduleAt parameter, despite the frontend code showing toISOString() usage in the ScheduleSendPicker component.
Learnt from: danteissaias
PR: Mail-0/Zero#458
File: apps/mail/lib/email-utils.ts:91-134
Timestamp: 2025-03-16T23:15:24.659Z
Learning: According to RFC 2369, when processing list-unsubscribe headers with multiple URLs, the client should use the leftmost protocol that it supports (process URLs from left to right).
apps/mail/hooks/use-optimistic-actions.ts (1)
Learnt from: retrogtx
PR: Mail-0/Zero#1328
File: apps/mail/lib/hotkeys/mail-list-hotkeys.tsx:202-209
Timestamp: 2025-06-18T17:26:50.918Z
Learning: In apps/mail/lib/hotkeys/mail-list-hotkeys.tsx, the switchCategoryByIndex function using hardcoded indices for category hotkeys does not break when users reorder categories, contrary to the theoretical index-shifting issue. The actual implementation has constraints or mechanisms that prevent hotkey targeting issues.
🧬 Code Graph Analysis (3)
apps/mail/components/mail/mail-list.tsx (1)
apps/mail/hooks/use-threads.ts (1)
useThreads(13-61)
apps/mail/components/mail/thread-display.tsx (1)
apps/mail/lib/utils.ts (1)
formatFileSize(224-230)
apps/mail/hooks/use-optimistic-actions.ts (2)
apps/server/src/routes/chat.ts (2)
markAsRead(242-246)markAsRead(786-791)apps/server/src/lib/driver/google.ts (1)
markAsRead(115-134)
🪛 Biome (1.9.4)
apps/mail/components/mail/mail-list.tsx
[error] 73-73: Unexpected empty object pattern.
(lint/correctness/noEmptyPattern)
🔇 Additional comments (9)
apps/mail/hooks/use-summary.ts (1)
20-27: Excellent caching optimization!The addition of a 1-hour stale time and disabling automatic refetching behaviors will significantly reduce unnecessary network requests and improve performance. This aligns perfectly with the PR's goal of TanStack Query caching improvements.
apps/mail/hooks/use-notes.tsx (1)
19-21: Consistent caching improvements applied.The disabled refetching behaviors are consistent with the broader caching optimization effort across the application. This will prevent unnecessary data fetching and improve user experience.
apps/mail/components/mail/mail-list.tsx (1)
852-853: Correct removal of unnecessary await keywords.The removal of
awaitkeywords fromsetThreadIdandsetDraftIdcalls is correct since these are synchronous operations fromuseQueryState. This cleanup improves code clarity and performance.apps/mail/components/mail/thread-display.tsx (2)
517-638: Clean template string formatting.The simplified formatting of the template strings improves code readability while maintaining the same functionality. The compact
.map()calls are easier to follow.
982-983: Ignore outdated unsubscribe condition suggestionThe current code in apps/mail/components/mail/thread-display.tsx still correctly shows the unsubscribe option when either
listUnsubscribeorlistUnsubscribePostis present:{emailData.latest?.listUnsubscribe || emailData.latest?.listUnsubscribePost ? ( <DropdownMenuItem onClick={handleUnsubscribeProcess}> … </DropdownMenuItem> ) : null}No narrowing to only
listUnsubscribePosthas been applied—both headers remain supported per RFC 2369. You can disregard the original review comment.Likely an incorrect or invalid review comment.
apps/mail/hooks/use-optimistic-actions.ts (4)
185-214: Excellent useCallback optimization for optimisticMarkAsRead.The conversion to
useCallbackwith proper dependencies and functional state updates will prevent unnecessary re-renders and ensure the latest state is used. The dependency array correctly includes all external values used within the callback.
244-271: Proper useCallback implementation for optimisticToggleStar.The memoization and dependency management follow React best practices. The function will only be recreated when its dependencies change, improving performance.
382-411: Consistent useCallback pattern for optimisticToggleImportant.The implementation maintains consistency with the other optimistic action functions while properly handling dependencies and state updates.
204-204: Correct functional state updates.Using
setMail((prev) => ({ ...prev, bulkSelected: [] }))instead ofsetMail({ ...mail, bulkSelected: [] })ensures the latest state is used, preventing potential race conditions in concurrent updates.Also applies to: 401-401
… improvements, callbacks where needed in optimistic actions hook, some formatting
Description
Please provide a clear description of your changes.
Type of Change
Please delete options that are not relevant.
Areas Affected
Please check all that apply:
Testing Done
Describe the tests you've done:
Security Considerations
For changes involving data or authentication:
Checklist
Additional Notes
Add any other context about the pull request here.
Screenshots/Recordings
Add screenshots or recordings here if applicable.
By submitting this pull request, I confirm that my contribution is made under the terms of the project's license.
Summary by CodeRabbit
Bug Fixes
Refactor