mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-17 09:51:35 +00:00
Merge 76a681de20 into 40a9fba81f
This commit is contained in:
commit
64afa0c87c
1 changed files with 23 additions and 5 deletions
|
|
@ -935,8 +935,10 @@
|
|||
`chat-input${chatIdProp ? `-${chatIdProp}` : ''}`
|
||||
);
|
||||
|
||||
const navigatedChatId = chatIdProp;
|
||||
const loaded = chatIdProp ? await loadChat() : false;
|
||||
noteChatDebug('loadChat completed inside navigateHandler', { loaded });
|
||||
if (chatIdProp !== navigatedChatId) return;
|
||||
if (loaded) {
|
||||
await tick();
|
||||
loading = false;
|
||||
|
|
@ -1425,14 +1427,16 @@
|
|||
if (!id || $temporaryChatEnabled) return Promise.resolve();
|
||||
if (chatRefresh?.id === id) return chatRefresh.promise;
|
||||
const baseline = { ...history.messages };
|
||||
const loadCountAtStart = chatLoadCount;
|
||||
const promise = (async () => {
|
||||
try {
|
||||
const fresh = await getChatById(localStorage.token, id);
|
||||
if ($chatId !== id || joinedChatId !== id) return;
|
||||
if (chatLoadCount !== loadCountAtStart) return;
|
||||
chat = fresh;
|
||||
mergeChatMessages(fresh.chat.history, baseline);
|
||||
} catch (error) {
|
||||
if ($chatId === id && joinedChatId === id) {
|
||||
if ($chatId === id && joinedChatId === id && chatLoadCount === loadCountAtStart) {
|
||||
clearPresence();
|
||||
chat = null;
|
||||
history = { messages: {}, currentId: null };
|
||||
|
|
@ -2883,7 +2887,16 @@
|
|||
messageInput?.focus({ preventScroll: true });
|
||||
};
|
||||
|
||||
const loadChat = async () => {
|
||||
let chatLoadCount = 0;
|
||||
let latestChatLoad: Promise<boolean | null | undefined> | null = null;
|
||||
|
||||
// Overlapping loads and refreshes must not lay an older copy of the chat over a newer one.
|
||||
const loadChat = () => {
|
||||
latestChatLoad = fetchAndShowChat(++chatLoadCount);
|
||||
return latestChatLoad;
|
||||
};
|
||||
|
||||
const fetchAndShowChat = async (loadId: number) => {
|
||||
if (chatIdProp && chatIdProp !== $chatId) {
|
||||
terminalContext = null;
|
||||
history = { messages: {}, currentId: null };
|
||||
|
|
@ -2899,17 +2912,19 @@
|
|||
temporaryChatEnabled.set(false);
|
||||
}
|
||||
|
||||
chat = await getChatById(localStorage.token, $chatId).catch(async (error) => {
|
||||
const loadedChat = await getChatById(localStorage.token, $chatId).catch(async (error) => {
|
||||
console.error('[note-chat] getChatById failed', {
|
||||
chatIdProp,
|
||||
activeChatId: $chatId,
|
||||
error
|
||||
});
|
||||
if (!embedded) {
|
||||
if (!embedded && loadId === chatLoadCount) {
|
||||
await goto('/');
|
||||
}
|
||||
return null;
|
||||
});
|
||||
if (loadId !== chatLoadCount) return latestChatLoad;
|
||||
chat = loadedChat;
|
||||
noteChatDebug('getChatById completed', {
|
||||
found: !!chat,
|
||||
chatId: chat?.id,
|
||||
|
|
@ -2918,7 +2933,7 @@
|
|||
});
|
||||
|
||||
if (chat) {
|
||||
tags = await getTagsById(localStorage.token, $chatId).catch(async (error) => {
|
||||
const loadedTags = await getTagsById(localStorage.token, $chatId).catch(async (error) => {
|
||||
console.warn('[note-chat] getTagsById failed; continuing without tags', {
|
||||
chatIdProp,
|
||||
activeChatId: $chatId,
|
||||
|
|
@ -2926,6 +2941,8 @@
|
|||
});
|
||||
return [];
|
||||
});
|
||||
if (loadId !== chatLoadCount) return latestChatLoad;
|
||||
tags = loadedTags;
|
||||
noteChatDebug('getTagsById completed', { tagCount: tags?.length ?? 0 });
|
||||
|
||||
const chatContent = chat.chat;
|
||||
|
|
@ -3020,6 +3037,7 @@
|
|||
});
|
||||
return [];
|
||||
});
|
||||
if (loadId !== chatLoadCount) return latestChatLoad;
|
||||
noteChatDebug('task reconciliation completed', {
|
||||
pendingTaskCount: pendingTaskIds.length,
|
||||
hasCurrentMessage: !!currentMessage
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue