Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message editing not working correctly in chat application #24

Open
ibelick opened this issue Apr 7, 2025 · 0 comments
Open

Message editing not working correctly in chat application #24

ibelick opened this issue Apr 7, 2025 · 0 comments

Comments

@ibelick
Copy link
Owner

ibelick commented Apr 7, 2025

When editing a user message in the chat, the database is not correctly updating the message content, and the AI response doesn't regenerate based on the edited content. Instead, it continues to respond to the original message content.

Steps to Reproduce

  1. Send a message (e.g., "hello, give me one word!")
  2. Receive an AI response
  3. Edit the user message (e.g., to "hello, give me two words!")
  4. The AI still responds to the original message content, not the edited version

Technical Analysis
The issue stems from two key problems:

  1. Database Message Handling: When editing a message, we need to:
  • Delete the original user message from the database
  • Delete all assistant messages that came after it
  • Insert the new edited message with the same timestamp
  • Trigger a new AI response
  1. Client-Side State Management: The UI correctly updates to show only the edited message, but the backend doesn't match this state.

Current Implementation
Our current edit implementation updates the UI but doesn't properly sync with the database:

const handleEdit = async (id: string, newText: string) => {
  // Updates UI state to remove trailing messages
  setMessages((prev) => [
    ...prev.slice(0, messageIndex),
    { ...messageToEdit, content: newText },
  ])
  
  // Attempts to call API endpoint but database changes aren't properly implemented
  // Reload doesn't get fresh content because the database still has the old messages
}

Suggested Fix
We need to implement:

  1. A proper API endpoint (/api/delete-message-after) that:
  • Finds the original message by ID
  • Deletes all messages in the chat after the edited message's timestamp
  • Inserts the new message with the edited content
  • Returns success status
  1. More robust error handling and UI feedback during the edit process
  2. Ensure reload() is only called after successful database update

Priority
High - This affects core functionality of the chat application and creates a confusing user experience.

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

No branches or pull requests

1 participant