From d06789b8dc0dec083e268caddc2aa75ada062551 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Mon, 19 May 2025 00:39:19 +0300 Subject: [PATCH] Check for chat changed before displaying welcome panel --- public/scripts/welcome-screen.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/public/scripts/welcome-screen.js b/public/scripts/welcome-screen.js index ee98bc2fb..edbe21f0d 100644 --- a/public/scripts/welcome-screen.js +++ b/public/scripts/welcome-screen.js @@ -54,7 +54,14 @@ export async function openWelcomeScreen() { return; } - await sendWelcomePanel(); + const recentChats = await getRecentChats(); + const chatAfterFetch = getCurrentChatId(); + if (chatAfterFetch !== currentChatId) { + console.debug('Chat changed while fetching recent chats.'); + return; + } + + await sendWelcomePanel(recentChats); sendAssistantMessage(); sendWelcomePrompt(); } @@ -86,7 +93,11 @@ function sendWelcomePrompt() { addOneMessage(message, { scroll: false }); } -async function sendWelcomePanel() { +/** + * Sends the welcome panel to the chat. + * @param {RecentChat[]} chats List of recent chats + */ +async function sendWelcomePanel(chats) { try { const chatElement = document.getElementById('chat'); const sendTextArea = document.getElementById('send_textarea'); @@ -94,7 +105,6 @@ async function sendWelcomePanel() { console.error('Chat element not found'); return; } - const chats = await getRecentChats(); const templateData = { chats, empty: !chats.length,