Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/ai-assistant/src/components/ai-assistant-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,21 @@ export function AiAssistantComponent() {
}, [datasetMetaData]);

const onRestartAssistant = async () => {
// Clear Redux state first
dispatch(updateAiAssistantMessages([]));


// Clear library's internal state
try {
await restartChatRef.current();
} catch (e) {
console.error('Error restarting chat:', e);
}

setRestartKey(prev => prev + 1);

// Force remount after state has been cleared
// Use setTimeout to ensure Redux state update has propagated
Comment on lines +118 to +120
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setTimeout schedules a state update that can still fire after AiAssistantComponent unmounts (e.g., when switching to config view or closing the panel), which can trigger React warnings and unnecessary work. Consider storing the timeout id in a ref and clearing it in a useEffect cleanup (or guarding the callback with an isMounted ref) before calling setRestartKey.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot check if this comment makes sense and if yes, apply changes based on this feedback

setTimeout(() => {
setRestartKey(prev => prev + 1);
}, 0);
};

const onMessagesUpdated = (messages: MessageModel[]) => {
Expand Down
Loading