Skip to content

Commit 905aff8

Browse files
committed
fix: prevent sidebar clearing when opening new query tab (#576)
Two fixes: 1. EditorTabPayload.isConnectionOnly now excludes isNewTab payloads. The "+" button creates a payload with isNewTab:true which was incorrectly classified as connection-only, causing initializeAndRestoreTabs to skip the proper new-tab path and potentially fall into restoreFromDisk which clears session.tables. 2. Skip loadSchemaIfNeeded() when other windows already exist for the same connection. The schema is already loaded by the first window, and the concurrent driver use (schema load + health monitor ping) can crash single-connection drivers like MySQL on high-latency Cloud connections.
1 parent 4654c57 commit 905aff8

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

TablePro/Models/Query/EditorTabPayload.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,10 @@ internal struct EditorTabPayload: Codable, Hashable {
9393
/// Whether this payload is a "connection-only" payload — just a connectionId
9494
/// with no specific tab content. Used by MainContentView to decide whether
9595
/// to create a default tab or restore tabs from storage.
96+
/// Note: isNewTab payloads (from the "+" button) are NOT connection-only —
97+
/// they are explicit requests to open a new query tab.
9698
internal var isConnectionOnly: Bool {
97-
tabType == .query && tableName == nil && initialQuery == nil
99+
tabType == .query && tableName == nil && initialQuery == nil && !isNewTab
98100
}
99101

100102
/// Create a payload from a persisted QueryTab for restoration

TablePro/Views/Main/MainContentView.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,13 @@ struct MainContentView: View {
450450
private func initializeAndRestoreTabs() async {
451451
guard !hasInitialized else { return }
452452
hasInitialized = true
453-
Task { await coordinator.loadSchemaIfNeeded() }
453+
454+
// Only load schema if this is the first window for this connection.
455+
// Additional windows share the same driver — concurrent schema load
456+
// races with health monitor pings and can crash single-connection drivers.
457+
if !WindowLifecycleMonitor.shared.hasOtherWindows(for: connection.id, excluding: windowId) {
458+
Task { await coordinator.loadSchemaIfNeeded() }
459+
}
454460

455461
// If payload provided a specific tab (not connection-only), execute its query immediately
456462
if let payload, !payload.isConnectionOnly {

0 commit comments

Comments
 (0)