From 62348d94c2b40435f56c348098f11dfef00ce317 Mon Sep 17 00:00:00 2001 From: kjh2064 Date: Sat, 15 Aug 2026 20:57:27 +0900 Subject: [PATCH] fix(fe): resolve tab overflow eviction and router synchronization bugs when closing active tabs --- frontend/src/shared/shell/KsTabs.vue | 10 ++++++++++ frontend/src/shared/shell/layoutStore.ts | 16 ++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/frontend/src/shared/shell/KsTabs.vue b/frontend/src/shared/shell/KsTabs.vue index ce87aa64..b6eeb82e 100644 --- a/frontend/src/shared/shell/KsTabs.vue +++ b/frontend/src/shared/shell/KsTabs.vue @@ -15,7 +15,17 @@ const handleTabClick = (path: string) => { const handleCloseTab = (event: Event, tabId: string) => { event.stopPropagation() + const wasActive = activeTabId.value === tabId layoutStore.closeTab(tabId) + + if (wasActive) { + const nextActiveTab = tabs.value.find(t => t.id === layoutStore.activeTabId) + if (nextActiveTab) { + router.push(nextActiveTab.path) + } else { + router.push('/home') + } + } } const handleCloseOther = (tabId: string) => { diff --git a/frontend/src/shared/shell/layoutStore.ts b/frontend/src/shared/shell/layoutStore.ts index 4cf14e21..719e36e2 100644 --- a/frontend/src/shared/shell/layoutStore.ts +++ b/frontend/src/shared/shell/layoutStore.ts @@ -45,24 +45,32 @@ export const useLayoutStore = defineStore('layout', () => { // Tab management const addTab = (tab: Omit) => { - // Check if tab already exists + // Standardize tab ID based on path to prevent duplicates + const tabId = tab.id || `tab-${tab.path}` const existing = openedTabs.value.find(t => t.path === tab.path) if (existing) { activeTabId.value = existing.id return } - // Respect max tabs limit + // Respect max tabs limit (FIFO eviction) if (openedTabs.value.length >= maxTabs.value) { - openedTabs.value.shift() // Remove oldest tab + // Find oldest tab that is NOT currently active if possible + const oldestIndex = openedTabs.value.findIndex(t => t.id !== activeTabId.value) + if (oldestIndex !== -1) { + openedTabs.value.splice(oldestIndex, 1) + } else { + openedTabs.value.shift() + } } const newTab: OpenedTab = { ...tab, + id: tabId, timestamp: Date.now(), } openedTabs.value.push(newTab) - activeTabId.value = tab.id + activeTabId.value = newTab.id saveTabs() }