fix(tabs): restore saved sql library content in detached windows

This commit is contained in:
Melody Ruch authored and GitHub committed 2026-09-04 14:45:04 +08:00
1 parent 5a3a6e2bb0
commit ca003c5e93
2 files changed
+111

No files matched your search

+15
View File
@@ -2376,6 +2376,21 @@ export const useQueryStore = defineStore("query", () => {
const restored = restoreOpenTabsPayload({ tabs: [handoff.tab], activeTabId: handoff.tabId });
const restoredTab = restored.tabs[0];
if (!restoredTab) throw new Error("Unable to restore detached tab");
// serializeOpenTabs() blanks `sql` for a clean saved-SQL-library tab to avoid
// duplicating on-disk state across app restarts, relying on hydrateSavedSqlTabs()
// to refill it afterwards. The detach handoff goes through the same serialization
// but skips that hydration step, so do it here too or the new window opens empty.
// A freshly created detached window never runs the main-window bootstrap that
// populates savedSqlStore's local file index, so useSavedSqlStore().ensureFileContent()
// can't find the file locally either — go straight to the backend instead.
if (restoredTab.savedSqlId && restoredTab.mode === "query" && !restoredTab.sql) {
const file = await api.loadSavedSqlFile(restoredTab.savedSqlId).catch(() => undefined);
if (file) {
restoredTab.title = restoredTab.customTitle ? restoredTab.title : file.name;
restoredTab.sql = file.sql;
restoredTab.originalSql = file.sql;
}
}
Object.assign(restoredTab, handoff.runtime);
if (handoff.resultCacheKey) {
restoredTab.resultCacheKey = handoff.resultCacheKey;