Skip to content

Comments

fix: Trigger refetch() after label creation toast completes#1889

Merged
MrgSub merged 3 commits intoMail-0:stagingfrom
ayushsharma74:fix/label-refetch-sonner-promise-finally
Aug 3, 2025
Merged

fix: Trigger refetch() after label creation toast completes#1889
MrgSub merged 3 commits intoMail-0:stagingfrom
ayushsharma74:fix/label-refetch-sonner-promise-finally

Conversation

@ayushsharma74
Copy link
Contributor

@ayushsharma74 ayushsharma74 commented Aug 2, 2025

Description

Fixes #1748 and #1687
Ensures refetch() is called after label creation by using Sonner’s finally callback in toast.promise to update ui state without manual reload.

Type of Change

Please delete options that are not relevant.

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • 🎨 UI/UX improvement

Areas Affected

Please check all that apply:

  • Email Integration (Gmail, IMAP, etc.)
  • User Interface/Experience
  • Authentication/Authorization
  • Data Storage/Management
  • API Endpoints
  • Documentation
  • Testing Infrastructure
  • Development Workflow
  • Deployment/Infrastructure

Testing Done

Describe the tests you've done:

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • Cross-browser testing (if UI changes)
  • Mobile responsiveness verified (if UI changes)

Security Considerations

For changes involving data or authentication:

  • No sensitive data is exposed
  • Authentication checks are in place
  • Input validation is implemented
  • Rate limiting is considered (if applicable)

Checklist

  • I have read the CONTRIBUTING document
  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in complex areas
  • I have updated the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix/feature works
  • All tests pass locally
  • Any dependent changes are merged and published

Additional Notes

Add any other context about the pull request here.

Screenshots/Recordings

Before (labels are not visible after creation)

cursorful-video-1754126244395.mp4

After

cursorful-video-1754126609359.mp4

By submitting this pull request, I confirm that my contribution is made under the terms of the project's license.


Summary by cubic

Fixed label list not updating after creating a new label by triggering refetch() once the creation toast completes. This ensures the label list always shows the latest changes.

Summary by CodeRabbit

  • Bug Fixes
    • Ensured that label data is refreshed after creating a new label, regardless of the outcome.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@jazzberry-ai
Copy link

jazzberry-ai bot commented Aug 2, 2025

Bug Report

Name Severity Example test case Description
Potential Race Condition in Label Creation Low Create a new label. The refetch function is called in the finally block of the toast promise, which might be executed before the toast notification disappears. This could cause a race condition where the UI is updated before the toast is dismissed, leading to a potentially jarring visual experience. A delay is added to the refetch call to mitigate this.

Comments? Email us.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 2, 2025

Walkthrough

A finally callback was added to the toast promise in the onSubmit function of the NavMain component. This ensures the refetch function is triggered after the label creation mutation, regardless of outcome. No other logic or control flow was changed.

Changes

Cohort / File(s) Change Summary
NavMain Label Refetch on Submit
apps/mail/components/ui/nav-main.tsx
Added a finally callback to trigger refetch after label creation mutation completes. No other logic modified.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant NavMain Component
    participant Toast
    participant Label API

    User->>NavMain Component: Submit new label
    NavMain Component->>Toast: Show toast (promise)
    Toast->>Label API: Create label
    Label API-->>Toast: Success or Failure
    Toast->>NavMain Component: finally callback
    NavMain Component->>NavMain Component: refetch labels
Loading

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Assessment against linked issues

Objective Addressed Explanation
Refresh labels after creation so new label appears without manual page reload (#1748)

Suggested labels

high priority, design

Poem

When labels are born, let them shine bright,
No need for a reload, they appear in plain sight.
A finally refetch, in code we entrust,
For seamless updates—now that’s a must!
🚀✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8b4b9a9 and 7d66c54.

📒 Files selected for processing (1)
  • apps/mail/components/ui/nav-main.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (AGENT.md)

**/*.{js,jsx,ts,tsx}: Use 2-space indentation
Use single quotes
Limit lines to 100 characters in width
Semicolons are required

Files:

  • apps/mail/components/ui/nav-main.tsx
**/*.{js,jsx,ts,tsx,css}

📄 CodeRabbit Inference Engine (AGENT.md)

Use Prettier with sort-imports and Tailwind plugins

Files:

  • apps/mail/components/ui/nav-main.tsx
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (AGENT.md)

Enable TypeScript strict mode

Files:

  • apps/mail/components/ui/nav-main.tsx
🧠 Learnings (5)
📓 Common learnings
Learnt from: AnjanyKumarJaiswal
PR: Mail-0/Zero#1732
File: apps/mail/components/create/email-composer.tsx:634-657
Timestamp: 2025-07-15T03:31:14.991Z
Learning: In draft deletion operations, using setTimeout with a delay (like 500ms) before showing success toast notifications improves UX by allowing UI state changes (like closing composers and clearing IDs) to complete before displaying the toast, preventing jarring immediate toast appearances that could disappear quickly during interface transitions.
Learnt from: danteissaias
PR: Mail-0/Zero#902
File: apps/mail/components/connection/add.tsx:77-77
Timestamp: 2025-05-07T16:55:46.513Z
Learning: For the "Upgrade" link in AddConnectionDialog, using a proper <button> element instead of a <span> with onClick is recognized as an accessibility improvement but was deferred as out of scope in PR #902 (CSS variables PR).
📚 Learning: in draft deletion operations, using settimeout with a delay (like 500ms) before showing success toas...
Learnt from: AnjanyKumarJaiswal
PR: Mail-0/Zero#1732
File: apps/mail/components/create/email-composer.tsx:634-657
Timestamp: 2025-07-15T03:31:14.991Z
Learning: In draft deletion operations, using setTimeout with a delay (like 500ms) before showing success toast notifications improves UX by allowing UI state changes (like closing composers and clearing IDs) to complete before displaying the toast, preventing jarring immediate toast appearances that could disappear quickly during interface transitions.

Applied to files:

  • apps/mail/components/ui/nav-main.tsx
📚 Learning: in apps/server/src/lib/driver/google.ts, the normalization of "draft" to "drafts" in the count() met...
Learnt from: retrogtx
PR: Mail-0/Zero#1734
File: apps/server/src/lib/driver/google.ts:211-221
Timestamp: 2025-07-15T06:46:33.349Z
Learning: In apps/server/src/lib/driver/google.ts, the normalization of "draft" to "drafts" in the count() method is necessary because the navigation item in apps/mail/config/navigation.ts has id: 'drafts' (plural) while the Google API returns "draft" (singular). The nav-main.tsx component matches stats by comparing stat.label with item.id, so the backend must return "drafts" for the draft counter badge to appear in the sidebar.

Applied to files:

  • apps/mail/components/ui/nav-main.tsx
📚 Learning: in the threadlabels prompt system, existing labels should not be automatically preserved. the ai age...
Learnt from: MrgSub
PR: Mail-0/Zero#1837
File: apps/server/src/lib/brain.fallback.prompts.ts:211-217
Timestamp: 2025-07-26T20:39:06.670Z
Learning: In the ThreadLabels prompt system, existing labels should not be automatically preserved. The AI agent should re-evaluate all labels (both existing and new) against the current thread summary and only return labels that currently apply to the thread content, even if it means dropping previously applied labels that are no longer relevant.

Applied to files:

  • apps/mail/components/ui/nav-main.tsx
📚 Learning: in apps/mail/lib/hotkeys/mail-list-hotkeys.tsx, the switchcategorybyindex function using hardcoded i...
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.

Applied to files:

  • apps/mail/components/ui/nav-main.tsx
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need 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)

  • @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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests 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.

@coderabbitai coderabbitai bot added design Improvements & changes to design & UX High Priority High Priority Work labels Aug 2, 2025
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.

cubic analysis

1 issue found across 1 file • Review in cubic

React with 👍 or 👎 to teach cubic. You can also tag @cubic-dev-ai to give feedback, ask questions, or re-run the review.

@jazzberry-ai
Copy link

jazzberry-ai bot commented Aug 2, 2025

Bug Report

Name Severity Example test case Description
Potential Race Condition in Label Refetch Medium 1. Create a label. 2. Simulate another part of the app invalidating the useLabels query immediately after label creation is initiated. Multiple refetch calls to update the label list can occur if other parts of the application invalidate the useLabels query concurrently. This patch reduces one source of duplication but doesn't eliminate all possibilities. Consider debouncing/throttling refetch or using a more robust state management solution.

Comments? Email us.

@jazzberry-ai
Copy link

jazzberry-ai bot commented Aug 3, 2025

Bug Report

Name Severity Example test case Description
Unnecessary refetch on error Low Simulate a failed label creation and observe that refetch is still called. The refetch function is called unconditionally in the finally block of the toast.promise function in apps/mail/components/ui/nav-main.tsx, even when the createLabel promise rejects. This results in an unnecessary data refresh after a failed label creation attempt.

Comments? Email us.

@MrgSub MrgSub merged commit c6fd1d8 into Mail-0:staging Aug 3, 2025
3 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Aug 4, 2025
34 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

design Improvements & changes to design & UX High Priority High Priority Work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Labes Refresh Issue

2 participants