tjtanjin / react-chatbotify

A modern React library for creating a flexible and extensible chatbot.
https://react-chatbotify.com
MIT License
135 stars 65 forks source link

[Bug] duplicate messages #5

Closed theodor961 closed 9 months ago

theodor961 commented 9 months ago

when setting chatHistory:{disabled:true} , the first 2 messages are always a duplicate,

i solved it by simply adding the following in ChatBotContainer.tsx line 108 (an empty message if history is disabled ) but i don't think that's a good way to fix it , so if you can find the bug it would be amazing , best of luck!

if (botOptions.chatHistory?.disabled) { localStorage.removeItem(botOptions.chatHistory?.storageKey as string); //added to prevent bug const messageContent = { content: <></>, type: "object", isUser: false, timestamp: null, }; setMessages([messageContent]);

tjtanjin commented 9 months ago

Hey @theodor961, thank you for reporting this! I should be able to take a look at this later tonight. In the meantime, if it's alright with you, would you be able to share screenshots showing the duplicate messages along with your bot configurations?

theodor961 commented 9 months ago

my pleasure,

i used the default flow and default bot options <ChatBot options={{chatHistory:{disabled:true}}}/>

below you can find the screenshoted result Screenshot 2023-12-05 051202

tjtanjin commented 9 months ago

@theodor961 Can I check if you're seeing this only in development environment? The issue is not reproducible on the playground. Any chance this is relevant for you?

tjtanjin commented 9 months ago

Hey @theodor961! Just to share some observations:

Based on the above, I would assume StrictMode (refer to link in above comment) in react 18 is what is causing the duplicate message seen. There are some suggested workarounds online so I leave that exploration up to you 😝

Thank you for raising this up and I'll update the documentation to include this piece of information in case others come across the same issue in future.

That said, if you feel I am mistaken and you are still facing the issue even without StrictMode, kindly let me know and I'll try my best to look again 😀

theodor961 commented 9 months ago

okay, perfect!

thanks for checking it out, you have an amazing product.

tjtanjin commented 9 months ago

okay, perfect!

thanks for checking it out, you have an amazing product.

No problem, I'm happy to know there's someone benefitting from it 😀

Feel free to reach out if you have anymore questions/issues!

Edit: Updated docs with a FAQ