From 8efa7e2de6b595e45d2a56f0e8f68392a98ecd93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=9B=BD=E9=94=8B?= Date: Wed, 18 Mar 2026 21:24:45 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix(App/handleNewQuery):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=B0=E5=BB=BA=E6=9F=A5=E8=AF=A2=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=95=B0=E6=8D=AE=E5=BA=93=E9=80=89=E6=8B=A9=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 验证当前 tab 的 connectionId 仍存在于 connections 列表中才复用上下文 - activeContext 作为次优先回退,同样验证 connectionId 有效性 - 避免关闭连接 A 后新建查询仍默认选中数据库 A 的问题 - refs #241 --- frontend/src/App.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index ccff62a..2c38879 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -911,18 +911,24 @@ function App() { }, []); const handleNewQuery = () => { - let connId = activeContext?.connectionId || ''; - let db = activeContext?.dbName || ''; + let connId = ''; + let db = ''; - // Priority: Active Tab Context > Sidebar Selection + // Priority: Active Tab Context (if connection still valid) > Sidebar Selection (activeContext) if (activeTabId) { const currentTab = tabs.find(t => t.id === activeTabId); - if (currentTab && currentTab.connectionId) { + if (currentTab && currentTab.connectionId && connections.some(c => c.id === currentTab.connectionId)) { connId = currentTab.connectionId; db = currentTab.dbName || ''; } } + // Fallback: Sidebar selection context (only if connection still valid) + if (!connId && activeContext?.connectionId && connections.some(c => c.id === activeContext.connectionId)) { + connId = activeContext.connectionId; + db = activeContext.dbName || ''; + } + addTab({ id: `query-${Date.now()}`, title: '新建查询',