Check for chat changed before displaying welcome panel
| @@ -54,7 +54,14 @@ export async function openWelcomeScreen() { | ||
| 54 | 54 | return; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | 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); | |
| 58 | 65 | sendAssistantMessage(); |
| 59 | 66 | sendWelcomePrompt(); |
| 60 | 67 | } |
| @@ -86,7 +93,11 @@ function sendWelcomePrompt() { | ||
| 86 | 93 | addOneMessage(message, { scroll: false }); |
| 87 | 94 | } |
| 88 | 95 | |
| 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) { | |
| 90 | 101 | try { |
| 91 | 102 | const chatElement = document.getElementById('chat'); |
| 92 | 103 | const sendTextArea = document.getElementById('send_textarea'); |
| @@ -94,7 +105,6 @@ async function sendWelcomePanel() { | ||
| 94 | 105 | console.error('Chat element not found'); |
| 95 | 106 | return; |
| 96 | 107 | } |
| 97 | - const chats = await getRecentChats(); | |
| 98 | 108 | const templateData = { |
| 99 | 109 | chats, |
| 100 | 110 | empty: !chats.length, |