fix(ui): Prevent infinite loop when displaying error toast in chat

This commit is contained in:
Richard Palethorpe
2025-04-01 21:54:59 +01:00
parent e90c192063
commit 7494aa9c26
2 changed files with 11 additions and 3 deletions

View File

@@ -150,6 +150,11 @@ export function useChat(agentName) {
localMessageContents.current.clear(); // Clear tracked local messages localMessageContents.current.clear(); // Clear tracked local messages
}, []); }, []);
// Clear error state
const clearError = useCallback(() => {
setError(null);
}, []);
return { return {
messages, messages,
sending, sending,
@@ -157,5 +162,6 @@ export function useChat(agentName) {
isConnected, isConnected,
sendMessage, sendMessage,
clearChat, clearChat,
clearError,
}; };
} }

View File

@@ -15,7 +15,8 @@ function Chat() {
error, error,
isConnected, isConnected,
sendMessage, sendMessage,
clearChat clearChat,
clearError
} = useChat(name); } = useChat(name);
// Scroll to bottom when messages change // Scroll to bottom when messages change
@@ -27,8 +28,9 @@ function Chat() {
useEffect(() => { useEffect(() => {
if (error) { if (error) {
showToast(error, 'error'); showToast(error, 'error');
clearError();
} }
}, [error, showToast]); }, [error, showToast, clearError]);
// Handle form submission // Handle form submission
const handleSubmit = async (e) => { const handleSubmit = async (e) => {
@@ -115,7 +117,7 @@ function Chat() {
placeholder="Type your message... (Press Enter to send, Shift+Enter for new line)" placeholder="Type your message... (Press Enter to send, Shift+Enter for new line)"
disabled={sending || !isConnected} disabled={sending || !isConnected}
className="form-control" className="form-control"
rows={2} rows={5}
style={{ flex: 1, resize: 'vertical', minHeight: '38px', maxHeight: '150px' }} style={{ flex: 1, resize: 'vertical', minHeight: '38px', maxHeight: '150px' }}
/> />
<button <button