fix(sidebar): preserve connection node during metadata refresh

This commit is contained in:
t8y2 2026-07-16 23:07:35 +08:00
parent 6660957153
commit 7b356ddb22
2 changed files with 30 additions and 1 deletions

View File

@ -74,6 +74,33 @@ describe("connectionStore database info", () => {
expect(store.connectedIds.has(config.id)).toBe(true);
});
it("preserves the connection tree node while background database info is stored", async () => {
const config = mysqlConnection();
const saveConnectionDatabaseInfo = vi.fn().mockResolvedValue(undefined);
vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
vi.doMock("@/lib/backend/api", () => ({
connectDb: vi.fn().mockResolvedValue(config.id),
connectionDatabaseInfo: vi.fn().mockResolvedValue({ productName: "MySQL", productVersion: "8.0.34" }),
saveConnectionDatabaseInfo,
saveConnections: vi.fn().mockResolvedValue(undefined),
saveSidebarLayout: vi.fn().mockResolvedValue(undefined),
connectionIdentifierQuote: vi.fn().mockResolvedValue(undefined),
}));
const { useConnectionStore } = await import("@/stores/connectionStore");
const store = useConnectionStore();
await store.addConnection(config);
const connectionNode = store.treeNodes[0];
await store.connect(config);
await vi.waitFor(() => expect(saveConnectionDatabaseInfo).toHaveBeenCalled());
expect(store.treeNodes[0]).toBe(connectionNode);
expect(store.getConfig(config.id)?.database_info?.productVersion).toBe("8.0.34");
expect(store.connectedIds.has(config.id)).toBe(true);
});
it("does not delay connection success while optional metadata is loading", async () => {
const config = mysqlConnection();
let resolveDatabaseInfo!: (value: { productName: string; productVersion: string }) => void;

View File

@ -1811,7 +1811,9 @@ export const useConnectionStore = defineStore("connection", () => {
const nextConnections = [...connections.value];
nextConnections[index] = { ...nextConnections[index], database_info: normalized };
connections.value = nextConnections;
rebuildTreeNodes();
// Database info is reactive connection metadata, not tree structure. Keep
// navigator node identities stable so an in-flight first expansion can
// still apply its loaded children after this background refresh completes.
}
async function refreshConnectedDatabaseInfo(connectionId: string, config: ConnectionConfig): Promise<void> {