mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-19 16:16:45 +00:00
fix(sql-library): hydrate restored tabs after startup
This commit is contained in:
@@ -3895,13 +3895,14 @@ function onLoginSuccess() {
|
||||
async function initApp() {
|
||||
const t0 = performance.now();
|
||||
console.log("[STARTUP] initApp begin");
|
||||
void Promise.all([initSavedSqlEditorPositions(), savedSqlStore.initFromStorage()])
|
||||
const savedSqlInitialization = Promise.all([initSavedSqlEditorPositions(), savedSqlStore.initFromStorage()])
|
||||
.then(() => {
|
||||
console.log(`[STARTUP] savedSqlStore.initFromStorage: ${(performance.now() - t0).toFixed(0)}ms`);
|
||||
void queryStore.hydrateSavedSqlTabs();
|
||||
return true;
|
||||
})
|
||||
.catch((e: any) => {
|
||||
toast(t("connection.loadFailed", { message: e?.message || String(e) }), 5000);
|
||||
return false;
|
||||
});
|
||||
|
||||
const restoreOpenTabs = async () => {
|
||||
@@ -3931,6 +3932,13 @@ async function initApp() {
|
||||
onOptionalStateError: (error) => console.error("[STARTUP] settingsStore.initAiConfigs failed", error),
|
||||
});
|
||||
}
|
||||
void savedSqlInitialization
|
||||
.then((initialized) => {
|
||||
if (initialized) return queryStore.hydrateSavedSqlTabs();
|
||||
})
|
||||
.catch((e: any) => {
|
||||
toast(t("connection.loadFailed", { message: e?.message || String(e) }), 5000);
|
||||
});
|
||||
await runPendingComponentUpdatesBeforePluginReconnect({
|
||||
hasPendingComponentUpdates: () => !isDetachedWindowContext && hasPendingComponentUpdatesAfterAppRestart(),
|
||||
prepareStartup: async () => {
|
||||
|
||||
@@ -65,11 +65,13 @@ test("web startup uses the guarded initializer behind the existing authenticatio
|
||||
const webInitialization = initAppSource.indexOf("await initializeOpenTabs({");
|
||||
const optionalInitialization = initAppSource.indexOf("initializeOptionalState: () => settingsStore.initAiConfigs()", webInitialization);
|
||||
const requiredRestoration = initAppSource.indexOf("restoreOpenTabs,", optionalInitialization);
|
||||
const savedSqlHydration = initAppSource.indexOf("queryStore.hydrateSavedSqlTabs()", requiredRestoration);
|
||||
assert.ok(savedSqlInitialization >= 0);
|
||||
assert.ok(webInitialization >= 0);
|
||||
assert.ok(savedSqlInitialization < webInitialization);
|
||||
assert.ok(optionalInitialization > webInitialization);
|
||||
assert.ok(requiredRestoration > optionalInitialization);
|
||||
assert.ok(savedSqlHydration > requiredRestoration);
|
||||
assert.equal(initAppSource.includes("if (!desktopOpenTabsRestorationBarrier) await settingsStore.initAiConfigs()"), false);
|
||||
|
||||
const mountedStart = appSource.indexOf("onMounted(async () =>");
|
||||
|
||||
+36
@@ -379,6 +379,42 @@ test("clean saved SQL tabs persist without duplicating SQL text", async () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("clean saved SQL tabs hydrate after their tabs finish restoring", async () => {
|
||||
const restoreStorage = installMemoryStorage();
|
||||
const fullFile = {
|
||||
id: "saved-startup-race",
|
||||
connectionId: "conn-1",
|
||||
name: "startup.sql",
|
||||
database: "db",
|
||||
sql: "SELECT 1;",
|
||||
sqlLoaded: true,
|
||||
createdAt: "2026-09-27T00:00:00.000Z",
|
||||
updatedAt: "2026-09-27T00:00:00.000Z",
|
||||
};
|
||||
try {
|
||||
setActivePinia(createPinia());
|
||||
let store = useQueryStore();
|
||||
store.openSavedSql(fullFile);
|
||||
await store.flushPendingPersist();
|
||||
|
||||
disposePinia(getActivePinia()!);
|
||||
setActivePinia(createPinia());
|
||||
store = useQueryStore();
|
||||
const savedSqlStore = useSavedSqlStore();
|
||||
savedSqlStore.files = [fullFile];
|
||||
|
||||
await store.hydrateSavedSqlTabs();
|
||||
await store.initOpenTabs();
|
||||
await store.hydrateSavedSqlTabs();
|
||||
|
||||
const restored = store.tabs.find((tab) => tab.savedSqlId === fullFile.id);
|
||||
assert.equal(restored?.sql, fullFile.sql);
|
||||
assert.equal(restored?.originalSql, fullFile.sql);
|
||||
} finally {
|
||||
restoreStorage();
|
||||
}
|
||||
});
|
||||
|
||||
test("saved SQL opens with its saved execution target by default", async () => {
|
||||
const restoreStorage = installMemoryStorage();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user