Skip to content

Commit 2113b79

Browse files
committed
Abort active generation on new chat and history load
Updated handleNewChat and handleLoadHistory to abort any active generation before starting a new session or loading history. This prevents session merging and ensures clean transitions between chat sessions.
1 parent c950646 commit 2113b79

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/app/page.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,10 @@ export default function Home() {
484484
}, [isGenerating, handleCancel]);
485485

486486
const handleNewChat = useCallback(() => {
487-
if (isGenerating) {
488-
return; // Don't interrupt generation
487+
// Abort active generation if any
488+
if (abortControllerRef.current) {
489+
abortControllerRef.current.abort();
490+
abortControllerRef.current = null;
489491
}
490492
// Start new session
491493
setCurrentSessionId(uuidv4());
@@ -505,6 +507,12 @@ export default function Home() {
505507

506508

507509
const handleLoadHistory = (item: HistoryItem) => {
510+
// Abort any active generation to prevent session merging
511+
if (abortControllerRef.current) {
512+
abortControllerRef.current.abort();
513+
abortControllerRef.current = null;
514+
}
515+
508516
// Switch to the session of this item
509517
if (item.sessionId) {
510518
setCurrentSessionId(item.sessionId);

0 commit comments

Comments
 (0)