From ae2f59b82900082c4da9658b9c0363a76964ec47 Mon Sep 17 00:00:00 2001 From: Momentry Studio Date: Tue, 27 Oct 2026 17:25:19 +0800 Subject: [PATCH] fix: loadSessions variable shadowing bug - Local variable 'sessions' was shadowing the ref 'sessions' - sessions.value = sessions was not updating the ref - Renamed local variable to 'sessionList' and properly assign to sessions.value - This fixes sessions not appearing in history list after save --- src/composables/useSearchSession.ts | 10 ++++++---- src/views/SearchView.vue | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/composables/useSearchSession.ts b/src/composables/useSearchSession.ts index 21049fe..2f39f76 100644 --- a/src/composables/useSearchSession.ts +++ b/src/composables/useSearchSession.ts @@ -80,8 +80,8 @@ export function useSearchSession() { if (!resp.ok) throw new Error(`HTTP ${resp.status}`) const data = await resp.json() // Enrich sessions with last query from messages - const sessions = data.sessions || [] - for (const s of sessions) { + const sessionList = data.sessions || [] + for (const s of sessionList) { try { const msgResp = await fetch(`${base}/api/v2/search-sessions/${s.id}/messages?limit=1`, { headers: getAuthHeaders() @@ -95,7 +95,7 @@ export function useSearchSession() { } } catch {} } - sessions.value = sessions + sessions.value = sessionList } catch (e: any) { error.value = e.message || 'Failed to load sessions' } finally { @@ -117,7 +117,9 @@ export function useSearchSession() { if (!resp.ok) throw new Error(`HTTP ${resp.status}`) const data = await resp.json() await loadSessions() - return data.session + // Return the newly created session from the sessions list + const newSession = sessions.value.find(s => s.id === data.session?.id) + return newSession || data.session } catch (e: any) { error.value = e.message || 'Failed to create session' return null diff --git a/src/views/SearchView.vue b/src/views/SearchView.vue index 8612745..0792e98 100644 --- a/src/views/SearchView.vue +++ b/src/views/SearchView.vue @@ -765,7 +765,9 @@ async function saveCurrentSession() { // Show rename dialog for session name if (currentSession.value) { - renamingSession.value = currentSession.value + // Ensure we're working with the session from the list + const sessionFromList = sessionList.value.find(s => s.id === currentSession.value!.id) + renamingSession.value = sessionFromList || currentSession.value renameValue.value = currentSession.value.title === '未命名' ? '' : currentSession.value.title nextTick(() => renameInputEl.value?.focus()) }