Skip to content

fix: prevent duplicate user message when clicking chatbot suggested prompt#148

Merged
dory-finn merged 1 commit intomainfrom
fix/chatbot-duplicate-message-146
Apr 3, 2026
Merged

fix: prevent duplicate user message when clicking chatbot suggested prompt#148
dory-finn merged 1 commit intomainfrom
fix/chatbot-duplicate-message-146

Conversation

@solarhell
Copy link
Copy Markdown
Collaborator

Summary

Fixes #146

When clicking a suggested prompt on the Chatbot welcome page, the same user message appeared twice in the conversation. This was caused by a race condition between:

  1. sendMessage (triggered by the initialPrompt effect in chatbox.tsx) — adds the user message to local state and sends it to the API
  2. fetchSessionDetail (triggered by selectedSessionId change in session-controller.ts) — fetches messages from server, which may already include the just-sent message

The setMessages(initialMessages) call from fetchSessionDetail overwrote the local message state with server data that included the user message, while useChat also had the same message from sendMessage, causing duplication.

Fix: Skip setMessages(initialMessages) after the initial prompt has been submitted, preventing the race condition from overwriting local state.

Test plan

  • Click a suggested prompt on Chatbot welcome page — user message appears only once
  • Normal session switching still loads messages correctly
  • Build passes (tsc --noEmit)

…rompt (#146)

When clicking a suggested prompt, a race condition between sendMessage
(initialPrompt effect) and fetchSessionDetail (selectedSessionId effect)
could cause the same user message to appear twice. Skip overwriting
messages via setMessages after the initial prompt has been submitted.
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dory Ready Ready Preview, Comment Apr 3, 2026 5:01am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
dory-admin Ignored Ignored Apr 3, 2026 5:01am
dory-beta Ignored Ignored Apr 3, 2026 5:01am

Request Review

@dory-finn dory-finn merged commit 806c8d5 into main Apr 3, 2026
5 of 6 checks passed
@solarhell solarhell deleted the fix/chatbot-duplicate-message-146 branch April 3, 2026 05:29
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.

🐛 Bug Description

2 participants