Skip to content

messages appear twice fix#1589

Merged
simo6529 merged 3 commits intomainfrom
messages-appear-twice
Oct 31, 2025
Merged

messages appear twice fix#1589
simo6529 merged 3 commits intomainfrom
messages-appear-twice

Conversation

@simo6529
Copy link
Copy Markdown
Collaborator

@simo6529 simo6529 commented Oct 31, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Improved drop processing and real-time stream updates for better data consistency.

Signed-off-by: Simo <simo@6529.io>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Oct 31, 2025

Walkthrough

The CreateDrop component is modified to handle incoming drops on the client side following a successful server mutation. A processIncomingDrop handler is integrated into the addDropMutation's onSuccess callback, and the mutationFn behavior is adjusted to return the API result without awaiting.

Changes

Cohort / File(s) Change Summary
Drop Processing Enhancement
components/waves/CreateDrop.tsx
Imports ProcessIncomingDropType and processIncomingDrop from useMyStream; adds onSuccess handler to addDropMutation that calls processDropRemoved when dropId exists, then calls processIncomingDrop with serverDrop and DROP_INSERT type; changes mutationFn to return commonApiPost result directly instead of awaiting

Sequence Diagram

sequenceDiagram
    participant User
    participant CreateDrop
    participant Server
    participant useMyStream

    User->>CreateDrop: Add Drop
    CreateDrop->>Server: commonApiPost (addDropMutation)
    Server-->>CreateDrop: serverDrop response
    Note over CreateDrop: onSuccess triggered
    
    rect rgb(200, 220, 240)
        CreateDrop->>useMyStream: processDropRemoved (if dropId exists)
        CreateDrop->>useMyStream: processIncomingDrop(serverDrop, DROP_INSERT)
    end
    
    useMyStream-->>CreateDrop: Drop processed locally
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Attention areas:
    • Verify that the onSuccess callback logic correctly handles the body.dropId conditional check
    • Confirm the order of processDropRemoved and processIncomingDrop calls is semantically correct
    • Ensure the mutationFn change from awaiting to returning doesn't alter error handling behavior or type contracts
    • Validate that ProcessIncomingDropType is properly utilized with DROP_INSERT constant

Poem

🐰 A drop flows in from the server's stream,
No more waiting—now we process the dream,
Remove the old, insert the new with care,
The rabbit hops through the async air! ✨

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "messages appear twice fix" is directly related to the changeset's objective. The PR modifies the drop mutation handler in CreateDrop.tsx to properly process incoming drops through an onSuccess callback, which addresses the root cause of duplicate message appearances. The title clearly conveys the problem being solved from the user's perspective and is specific enough that a teammate reviewing the git history would immediately understand the PR fixes a duplication issue. The title is concise, avoids generic language, and accurately reflects the main goal of the changes.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch messages-appear-twice

📜 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 ac2e2f8 and cd21ca0.

📒 Files selected for processing (1)
  • components/waves/CreateDrop.tsx (3 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursorrules)

**/*.{ts,tsx}: Do not include any comments in the code
Use react-query for data fetching
Always add readonly before props

Files:

  • components/waves/CreateDrop.tsx
**/*.tsx

📄 CodeRabbit inference engine (.cursorrules)

**/*.tsx: Use FontAwesome for icons
Use TailwindCSS for styling

Files:

  • components/waves/CreateDrop.tsx
🧬 Code graph analysis (1)
components/waves/CreateDrop.tsx (2)
contexts/wave/MyStreamContext.tsx (1)
  • useMyStream (243-249)
services/api/common-api.ts (1)
  • commonApiPost (166-191)
⏰ 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: Analyze (javascript-typescript)
🔇 Additional comments (4)
components/waves/CreateDrop.tsx (4)

28-28: LGTM!

The import is necessary for the new client-side drop processing logic.


63-63: LGTM!

The destructured functions are properly utilized in the mutation callbacks to handle client-side drop processing.


136-141: Functionally equivalent change.

Removing await and returning the promise directly works correctly with react-query. Both approaches are valid, though the explicit return is slightly more idiomatic.


142-147: Deduplication is properly handled via mergeDrops with stableKey logic.

The implementation correctly prevents duplicates. When processIncomingDrop is called with DROP_INSERT, it triggers updateData, which queues the operation. The processQueue function then calls mergeDrops, which deduplicates by stableKey—it creates a map of existing drops and overwrites any with matching keys, ensuring only the newest version persists. This same deduplication logic applies when waitAndInvalidateDrops() refetches data. For edits (when body.dropId exists), the two-step approach—processDropRemoved followed by processIncomingDrop—correctly removes the old drop before inserting the new one, making DROP_INSERT the appropriate choice in both scenarios.


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.

@sonarqubecloud
Copy link
Copy Markdown

@simo6529 simo6529 merged commit cbd81c9 into main Oct 31, 2025
8 checks passed
@simo6529 simo6529 deleted the messages-appear-twice branch October 31, 2025 13:23
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