Check for chat changed before displaying welcome panel

d06789b8dc0dec083e268caddc2aa75ada062551

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +13 -3Ignore whitespace
public/scripts/welcome-screen.js+13 -3
@@ -54,7 +54,14 @@ export async function openWelcomeScreen() {
5454 return;
5555 }
5656
5757 const recentChats = await sendWelcomePanelgetRecentChats();
58+ const chatAfterFetch = getCurrentChatId();
59+ if (chatAfterFetch !== currentChatId) {
60+ console.debug('Chat changed while fetching recent chats.');
61+ return;
62+ }
63+
64+ await sendWelcomePanel(recentChats);
5865 sendAssistantMessage();
5966 sendWelcomePrompt();
6067}
@@ -86,7 +93,11 @@ function sendWelcomePrompt() {
8693 addOneMessage(message, { scroll: false });
8794}
8895
89-async function sendWelcomePanel() {
96+/**
97+ * Sends the welcome panel to the chat.
98+ * @param {RecentChat[]} chats List of recent chats
99+ */
100+async function sendWelcomePanel(chats) {
90101 try {
91102 const chatElement = document.getElementById('chat');
92103 const sendTextArea = document.getElementById('send_textarea');
@@ -94,7 +105,6 @@ async function sendWelcomePanel() {
94105 console.error('Chat element not found');
95106 return;
96107 }
97- const chats = await getRecentChats();
98108 const templateData = {
99109 chats,
100110 empty: !chats.length,