lobehub / lobe-chat

๐Ÿคฏ Lobe Chat - an open-source, modern-design AI chat framework. Supports Multi AI Providers( OpenAI / Claude 3 / Gemini / Ollama / Azure / DeepSeek), Knowledge Base (file upload / knowledge management / RAG ), Multi-Modals (Vision/TTS) and plugin system. One-click FREE deployment of your private ChatGPT/ Claude application.
https://chat-preview.lobehub.com
Other
44.55k stars 9.99k forks source link

[Bug] Incorrect Display of Role Setting Input After Second Edit in Assistant Chat Interface #4688

Open wjsoj opened 2 days ago

wjsoj commented 2 days ago

๐Ÿ“ฆ Environment

Docker

๐Ÿ“Œ Version

1.31.5

๐Ÿ’ป Operating System

Other Linux

๐ŸŒ Browser

Chrome, Firefox

๐Ÿ› Bug Description

In the Assistant chat interface, there is an issue where editing the Role Setting a second time results in incorrect content being displayed in the input box.

๐Ÿ“ท Recurrence Steps

  1. Add a new Assistant.
  2. In the new chat interface, click the Edit button in the Role Setting at the top right corner.
  3. Modify the content and click OK. The content appears to be updated.
  4. Click the Edit button again and notice that the input box is empty and has not updated. (If there was a value in the Role Setting before modification, the input box will show the previous value instead of the new one after clicking Edit.)

๐Ÿšฆ Expected Behavior

I expected the input box to show the updated content after editing the Role Setting a second time.This will be helpful for people who want to Modify the Role Setting again after click OK.

๐Ÿ“ Additional Information

I have noticed that the issue is caused by the implementation in the lobe-ui component. The EditableMessage component internally specifies defaultValue to create a MessageInput component, but in the MessageInput component, defaultValue is handled as follows:

const [temporaryValue, setValue] = useState<string>(defaultValue || '');

This implementation retains the previous value in the input box, making it inconvenient for users to edit again.

Possible Solutions:

I hope a better solution can be found, and I would be happy to submit a PR.

lobehubbot commented 2 days ago

๐Ÿ‘€ @wjsoj

Thank you for raising an issue. We will investigate into the matter and get back to you as soon as possible. Please make sure you have given us as much context as possible.\ ้žๅธธๆ„Ÿ่ฐขๆ‚จๆไบค issueใ€‚ๆˆ‘ไปฌไผšๅฐฝๅฟซ่ฐƒๆŸฅๆญคไบ‹๏ผŒๅนถๅฐฝๅฟซๅ›žๅคๆ‚จใ€‚ ่ฏท็กฎไฟๆ‚จๅทฒ็ปๆไพ›ไบ†ๅฐฝๅฏ่ƒฝๅคš็š„่ƒŒๆ™ฏไฟกๆฏใ€‚

dosubot[bot] commented 2 days ago

Hey @wjsoj! I'm here to help you with any bugs, questions, or contributions. Let's work together to solve this issue.

The issue you're experiencing with the EditableMessage component in the Assistant chat interface seems to be related to how the defaultValue is handled in the MessageInput component. The current implementation retains the previous value, which causes the input box to not reflect the updated content after a second edit.

Here are a couple of potential solutions:

  1. Modify the EditableMessage Component:

    • You could add a unique key prop to the EditableMessage component in the SystemRoleContent.tsx file. This would force a re-render of the component whenever the key changes, ensuring that the input box displays the updated content. However, this approach might cause the modal to flicker, which could affect the user experience.
  2. Update the MessageInput Component:

    • Another approach is to modify the MessageInput component in the lobe-ui library to listen for changes to the defaultValue prop. This would involve updating the state whenever defaultValue changes, ensuring that the input box reflects the latest content. While this solution might add complexity to the UI component, it would provide a more seamless user experience.

Both solutions have their trade-offs, and the best approach depends on the desired user experience and the complexity you're willing to introduce into the codebase. If you're comfortable with the potential flicker, the first solution might be simpler to implement. Otherwise, updating the MessageInput component to handle defaultValue changes could provide a more robust solution.

To continue talking to Dosu, mention @dosu.

darxreborn commented 2 days ago

I submitted a similar issue at #4686

lobehubbot commented 2 days ago

Bot detected the issue body's language is not English, translate it automatically. ๐Ÿ‘ฏ๐Ÿ‘ญ๐Ÿป๐Ÿง‘โ€๐Ÿคโ€๐Ÿง‘๐Ÿ‘ซ๐Ÿง‘๐Ÿฟโ€๐Ÿคโ€๐Ÿง‘๐Ÿป๐Ÿ‘ฉ๐Ÿพโ€๐Ÿคโ€๐Ÿ‘จ๐Ÿฟ๐Ÿ‘ฌ๐Ÿฟ


I submitted a similar issue at #4686

wjsoj commented 2 days ago

I submitted a similar issue at #4686

I am unable to reproduce your issue in the local development environment. Your reported issue seems to be related to the logic of the tRPC interface and I don't understand why.