Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(plugins): preserve inactive workbench tab layout geometry

lxk9558da85d8800a6
diff --git a/apps/desktop/src/App.vue b/apps/desktop/src/App.vue
index 9871725720..49f469a240 100644
--- a/apps/desktop/src/App.vue
+++ b/apps/desktop/src/App.vue
@@ -660,7 +660,7 @@ function updatePluginAiRecommendations(tabId: string, update: PluginAiRecommenda
// iframe moved out of the DOM reloads from scratch, so KeepAlive/ContentArea
// remounts flash the whole webview and drop its live session state.
const mountedPluginWorkbenchTabs = computed(() => queryStore.tabs.filter((tab) => tab.mode === "plugin-workbench" && tab.pluginWorkbench));
-type PluginWorkbenchTabHandle = { refresh: () => Promise<unknown> };
+type PluginWorkbenchTabHandle = { refresh: () => Promise<unknown>; notifyLayout?: () => void };
const pluginWorkbenchTabRefs = new Map<string, PluginWorkbenchTabHandle>();
let detachedEventUnlisteners: Array<() => void> = [];
let floatingEventUnlisteners: Array<() => void> = [];
@@ -5621,7 +5621,7 @@ onUnmounted(() => {
</Dialog>
<div
v-show="!driverStoreActive && !pluginCenterActive && !settingsStore.settingsPageActive"
- class="flex min-h-0 min-w-0 flex-1"
+ class="relative flex min-h-0 min-w-0 flex-1"
:class="activeTab?.mode === 'plugin-workbench' && isVerticalTabPlacement ? (settingsStore.editorSettings.tabPlacement === 'right' ? 'flex-row-reverse' : 'flex-row') : 'flex-col'"
>
<div class="flex min-h-0" :class="activeTab?.mode === 'plugin-workbench' ? (isVerticalTabPlacement ? 'h-full flex-none flex-col' : 'flex-none flex-col') : 'flex-1 flex-col'">
@@ -5783,21 +5783,24 @@ onUnmounted(() => {
</SqlEditorWorkspace>
</div>
<!-- Always-mounted plugin workbench layer: switching tabs only
- toggles visibility, so plugin webviews (SSH terminals) are
- never destroyed and reloaded. SqlEditorWorkspace no longer
- renders plugin tabs — this layer owns them. It in turn
- yields the layout (display:none) while a plugin tab is
- active, or both flex-1 siblings would split the column. -->
- <div v-for="workbenchTab in mountedPluginWorkbenchTabs" :key="workbenchTab.id" v-show="activeTab && workbenchTab.id === activeTab.id" class="flex min-h-0 flex-1 flex-col">
- <PluginWorkbenchTab
- :ref="(element) => setPluginWorkbenchTabRef(workbenchTab.id, element)"
- :tab-id="workbenchTab.id"
- :plugin-id="workbenchTab.pluginWorkbench!.pluginId"
- :contribution-id="workbenchTab.pluginWorkbench!.contributionId"
- :context="workbenchTab.pluginWorkbench!.context"
- @close-tab="queryStore.closeTab(workbenchTab.id)"
- @recommendations="updatePluginAiRecommendations(workbenchTab.id, $event)"
- />
+ toggles visibility without destroying iframes. Inactive
+ tabs are preserved offscreen at full container bounds
+ (visibility:hidden, absolute inset-0) rather than display:none,
+ preventing terminal/layout collapse (0x0) during periodic
+ background redraws (#13734). -->
+ <div v-if="mountedPluginWorkbenchTabs.length > 0" class="relative min-h-0 min-w-0" :class="activeTab?.mode === 'plugin-workbench' ? 'flex flex-1 flex-col' : 'pointer-events-none absolute inset-0 -z-10 invisible size-full'">
+ <div v-for="workbenchTab in mountedPluginWorkbenchTabs" :key="workbenchTab.id" class="size-full min-h-0 flex-col" :class="activeTab && workbenchTab.id === activeTab.id ? 'relative flex flex-1' : 'pointer-events-none absolute inset-0 -z-10 invisible'">
+ <PluginWorkbenchTab
+ :ref="(element) => setPluginWorkbenchTabRef(workbenchTab.id, element)"
+ :tab-id="workbenchTab.id"
+ :active="activeTab?.id === workbenchTab.id"
+ :plugin-id="workbenchTab.pluginWorkbench!.pluginId"
+ :contribution-id="workbenchTab.pluginWorkbench!.contributionId"
+ :context="workbenchTab.pluginWorkbench!.context"
+ @close-tab="queryStore.closeTab(workbenchTab.id)"
+ @recommendations="updatePluginAiRecommendations(workbenchTab.id, $event)"
+ />
+ </div>
</div>
</div>
<PluginBottomDock v-if="!isDetachedWindowContext" />
diff --git a/apps/desktop/src/components/plugins/PluginBottomDock.vue b/apps/desktop/src/components/plugins/PluginBottomDock.vue
index 48d57c5e19..5ed9e77d36 100644
--- a/apps/desktop/src/components/plugins/PluginBottomDock.vue
+++ b/apps/desktop/src/components/plugins/PluginBottomDock.vue
@@ -640,11 +640,12 @@ onScopeDispose(() => window.removeEventListener("blur", onPlusMenuWindowBlur));
<X class="h-3.5 w-3.5" />
</Button>
</div>
- <div class="min-h-0 flex-1 overflow-hidden">
- <div v-for="entry in entries" v-show="entry.id === activeEntryId && !collapsed" :key="entry.id" class="h-full w-full">
+ <div class="relative min-h-0 flex-1 overflow-hidden">
+ <div v-for="entry in entries" :key="entry.id" class="size-full min-h-0" :class="entry.id === activeEntryId && !collapsed ? 'relative flex size-full' : 'pointer-events-none absolute inset-0 -z-10 invisible'">
<PluginWorkbenchHost
v-if="workbenchContributionFor(entry)"
:ref="setWorkbenchHostRef(entry.id)"
+ :active="entry.id === activeEntryId && !collapsed"
:plugin="definitionFor(entry.pluginId)!"
:contribution="workbenchContributionFor(entry)!"
:context="entry.context"
diff --git a/apps/desktop/src/components/plugins/PluginWorkbenchHost.spec.ts b/apps/desktop/src/components/plugins/PluginWorkbenchHost.spec.ts
index 90f8335fd8..3a72252ce6 100644
--- a/apps/desktop/src/components/plugins/PluginWorkbenchHost.spec.ts
+++ b/apps/desktop/src/components/plugins/PluginWorkbenchHost.spec.ts
@@ -449,4 +449,37 @@ describe("PluginWorkbenchHost initialization", () => {
),
);
});
+
+ it("posts a layout message to the iframe when active becomes true", async () => {
+ const activeRef = ref(false);
+ app = createApp({
+ components: { PluginWorkbenchHost },
+ setup() {
+ return { activeRef, plugin, contribution };
+ },
+ template: '<PluginWorkbenchHost :plugin="plugin" :contribution="contribution" :active="activeRef" />',
+ });
+ app.mount(root);
+ await flushWorkbenchLoad();
+
+ const frame = root.querySelector("iframe")!;
+ const target = frame.contentWindow!;
+ const postMessage = vi.spyOn(target, "postMessage").mockImplementation(() => {});
+
+ // Initially inactive: no layout message
+ expect(postMessage).not.toHaveBeenCalledWith(expect.objectContaining({ type: "layout" }), "*");
+
+ // Transition to active
+ activeRef.value = true;
+ await nextTick();
+ await vi.waitFor(() =>
+ expect(postMessage).toHaveBeenCalledWith(
+ expect.objectContaining({
+ source: "dbx-host",
+ type: "layout",
+ }),
+ "*",
+ ),
+ );
+ });
});
diff --git a/apps/desktop/src/components/plugins/PluginWorkbenchHost.vue b/apps/desktop/src/components/plugins/PluginWorkbenchHost.vue
index dc8ff4cac0..06a1d96452 100644
--- a/apps/desktop/src/components/plugins/PluginWorkbenchHost.vue
+++ b/apps/desktop/src/components/plugins/PluginWorkbenchHost.vue
@@ -41,10 +41,11 @@ const props = withDefaults(
plugin: InstalledPlugin;
contribution: PluginUiContribution;
context?: PluginWorkbenchContext;
+ active?: boolean;
setTitle?: (title: string | null) => Promise<void> | void;
getTitle?: () => Promise<string> | string;
}>(),
- { context: () => ({}) },
+ { context: () => ({}), active: true },
);
const emit = defineEmits<{
@@ -899,6 +900,20 @@ watch(
() => bridge?.updateTheme(currentBridgeTheme()),
);
+function notifyLayout(): void {
+ bridge?.notifyLayout();
+}
+
+watch(
+ () => props.active,
+ async (active) => {
+ if (active) {
+ await nextTick();
+ notifyLayout();
+ }
+ },
+);
+
/** §8.3/§7.4 two-phase close: parents await this before removing the entry so
* the plugin can release its workbench scope (PTY sessions, subscriptions);
* the bridge bounds the wait and resolves false on legacy/hung plugins. */
@@ -906,7 +921,7 @@ function requestClose(): Promise<boolean> {
return bridge ? bridge.requestWorkbenchClose() : Promise.resolve(false);
}
-defineExpose({ requestClose });
+defineExpose({ requestClose, notifyLayout });
onBeforeUnmount(() => {
disposed = true;
diff --git a/apps/desktop/src/components/plugins/PluginWorkbenchTab.spec.ts b/apps/desktop/src/components/plugins/PluginWorkbenchTab.spec.ts
index 8e5c35b738..b0341e7f14 100644
--- a/apps/desktop/src/components/plugins/PluginWorkbenchTab.spec.ts
+++ b/apps/desktop/src/components/plugins/PluginWorkbenchTab.spec.ts
@@ -256,4 +256,25 @@ describe("PluginWorkbenchTab restore self-heal", () => {
await vi.waitFor(() => expect(root.textContent).toContain("pluginPlatform.reloadRequired"));
expect(root.querySelector("iframe")).toBeNull();
});
+
+ it("forwards the active prop to PluginWorkbenchHost and exposes notifyLayout", async () => {
+ mocks.connectedIds.add("conn-1");
+ let tabInstance: any;
+ app = createApp({
+ components: { PluginWorkbenchTab },
+ setup() {
+ const tabRef = ref();
+ return { tabRef };
+ },
+ mounted() {
+ tabInstance = (this as any).tabRef;
+ },
+ template: '<PluginWorkbenchTab ref="tabRef" plugin-id="com.example.graph" contribution-id="graph.main" :active="false" />',
+ });
+ app.mount(root);
+
+ await vi.waitFor(() => expect(root.querySelector("iframe")).toBeInstanceOf(HTMLIFrameElement));
+ expect(typeof tabInstance?.notifyLayout).toBe("function");
+ expect(() => tabInstance.notifyLayout()).not.toThrow();
+ });
});
diff --git a/apps/desktop/src/components/plugins/PluginWorkbenchTab.vue b/apps/desktop/src/components/plugins/PluginWorkbenchTab.vue
index 00c906fecc..4e0136ea38 100644
--- a/apps/desktop/src/components/plugins/PluginWorkbenchTab.vue
+++ b/apps/desktop/src/components/plugins/PluginWorkbenchTab.vue
@@ -11,13 +11,17 @@ import { useQueryStore } from "@/stores/queryStore";
import { useI18n } from "vue-i18n";
import { useConnectionStore } from "@/stores/connectionStore";
-const props = defineProps<{
- tabId?: string;
- pluginId: string;
- contributionId: string;
- connectionId?: string;
- context?: PluginWorkbenchContext;
-}>();
+const props = withDefaults(
+ defineProps<{
+ tabId?: string;
+ active?: boolean;
+ pluginId: string;
+ contributionId: string;
+ connectionId?: string;
+ context?: PluginWorkbenchContext;
+ }>(),
+ { active: true },
+);
const { t, locale: appLocale } = useI18n();
const emit = defineEmits<{
@@ -158,10 +162,16 @@ function onGetTitle(): string {
return "";
}
+const hostRef = ref<{ requestClose: () => Promise<boolean>; notifyLayout?: () => void } | null>(null);
+
+function notifyLayout() {
+ hostRef.value?.notifyLayout?.();
+}
+
onMounted(start);
watch(() => [props.pluginId, props.contributionId, props.connectionId, props.context?.connectionId], start);
-defineExpose({ refresh });
+defineExpose({ refresh, notifyLayout });
</script>
<template>
@@ -174,7 +184,9 @@ defineExpose({ refresh });
</div>
<PluginWorkbenchHost
v-else
+ ref="hostRef"
class="min-h-0 flex-1"
+ :active="props.active"
:plugin="entry.plugin"
:contribution="entry.contribution"
:context="hostContext"
diff --git a/apps/desktop/src/components/plugins/__tests__/PluginWorkbenchInactiveLayout.spec.ts b/apps/desktop/src/components/plugins/__tests__/PluginWorkbenchInactiveLayout.spec.ts
new file mode 100644
index 0000000000..934080b0d7
--- /dev/null
+++ b/apps/desktop/src/components/plugins/__tests__/PluginWorkbenchInactiveLayout.spec.ts
@@ -0,0 +1,80 @@
+// @vitest-environment happy-dom
+
+import { createApp, defineComponent, h, ref } from "vue";
+import { describe, expect, it } from "vitest";
+
+describe("Plugin workbench tab inactive layout preservation (#13734)", () => {
+ it("preserves inactive tab containers at full bounds without collapsing to display:none", async () => {
+ const tabs = [
+ { id: "tab-ssh-1", title: "SSH 1", mode: "plugin-workbench" },
+ { id: "tab-ssh-2", title: "SSH 2", mode: "plugin-workbench" },
+ { id: "tab-http", title: "HTTP Client", mode: "plugin-workbench" },
+ ];
+ const activeTabId = ref("tab-ssh-1");
+
+ const root = document.createElement("div");
+ document.body.appendChild(root);
+
+ // Host workspace layer mirroring App.vue's mountedPluginWorkbenchTabs
+ const HostComponent = defineComponent({
+ setup() {
+ return { tabs, activeTabId };
+ },
+ template: `
+ <div class="relative flex size-full flex-col">
+ <div
+ v-for="tab in tabs"
+ :key="tab.id"
+ :data-testid="'container-' + tab.id"
+ class="size-full min-h-0 flex-col"
+ :class="activeTabId === tab.id
+ ? 'relative flex flex-1'
+ : 'pointer-events-none absolute inset-0 -z-10 invisible'"
+ >
+ <div :data-testid="'webview-' + tab.id" class="size-full">content-{{ tab.title }}</div>
+ </div>
+ </div>
+ `,
+ });
+
+ const app = createApp(HostComponent);
+ app.mount(root);
+
+ const c1 = root.querySelector<HTMLElement>("[data-testid='container-tab-ssh-1']")!;
+ const c2 = root.querySelector<HTMLElement>("[data-testid='container-tab-ssh-2']")!;
+ const c3 = root.querySelector<HTMLElement>("[data-testid='container-tab-http']")!;
+
+ // Initial state: tab-ssh-1 is active
+ expect(c1.classList.contains("relative")).toBe(true);
+ expect(c1.classList.contains("flex")).toBe(true);
+ expect(c1.classList.contains("flex-1")).toBe(true);
+ expect(c1.classList.contains("invisible")).toBe(false);
+
+ // Inactive tabs retain absolute inset-0 and invisible instead of display:none
+ expect(c2.classList.contains("absolute")).toBe(true);
+ expect(c2.classList.contains("inset-0")).toBe(true);
+ expect(c2.classList.contains("invisible")).toBe(true);
+ expect(c2.classList.contains("pointer-events-none")).toBe(true);
+ expect(c2.style.display).not.toBe("none");
+
+ expect(c3.classList.contains("absolute")).toBe(true);
+ expect(c3.classList.contains("inset-0")).toBe(true);
+ expect(c3.classList.contains("invisible")).toBe(true);
+ expect(c3.style.display).not.toBe("none");
+
+ // Switch to tab-ssh-2
+ activeTabId.value = "tab-ssh-2";
+ await new Promise((r) => setTimeout(r, 0));
+
+ expect(c1.classList.contains("invisible")).toBe(true);
+ expect(c1.classList.contains("absolute")).toBe(true);
+ expect(c1.style.display).not.toBe("none");
+
+ expect(c2.classList.contains("relative")).toBe(true);
+ expect(c2.classList.contains("flex-1")).toBe(true);
+ expect(c2.classList.contains("invisible")).toBe(false);
+
+ app.unmount();
+ root.remove();
+ });
+});
diff --git a/apps/desktop/src/lib/plugins/pluginHostBridge.spec.ts b/apps/desktop/src/lib/plugins/pluginHostBridge.spec.ts
index 80631776ff..299cc064d7 100644
--- a/apps/desktop/src/lib/plugins/pluginHostBridge.spec.ts
+++ b/apps/desktop/src/lib/plugins/pluginHostBridge.spec.ts
@@ -1842,7 +1842,9 @@ describe("plugin SDK source", () => {
onDragState: (listener: (active: boolean, position?: { x: number; y: number }) => void) => () => void;
onDrop: (listener: (files: unknown[], drop: unknown) => void) => () => void;
};
+ onLayout: (listener: (event: unknown) => void) => () => void;
};
+ dispatchEvent: ReturnType<typeof vi.fn>;
document: {
dispatchEvent: ReturnType<typeof vi.fn>;
};
@@ -1850,7 +1852,9 @@ describe("plugin SDK source", () => {
}
function loadSdk(posted: unknown[], initialTheme?: { appearance: "dark" | "light"; tokens: Record<string, string> }): SdkWindow {
- const sandbox = {} as SdkWindow;
+ const sandbox = {
+ dispatchEvent: vi.fn(),
+ } as unknown as SdkWindow;
const document = {
documentElement: {
dataset: {} as Record<string, string>,
@@ -2221,6 +2225,39 @@ describe("plugin SDK source", () => {
await expect(bridge.requestWorkbenchClose(5000)).resolves.toBe(false);
expect(messages.some((message) => message.type === "workbench/close")).toBe(true);
});
+
+ it("notifies the plugin of layout recalculations and dispatches window resize inside SDK", () => {
+ const messages: any[] = [];
+ const target = { postMessage: (message: unknown) => messages.push(message) } as unknown as Window;
+ const bridge = new PluginHostBridge(plugin(), workbench, {}, () => target, {
+ invoke: vi.fn(),
+ notify: vi.fn(),
+ sendBinary: vi.fn(),
+ readAsset: vi.fn(),
+ });
+
+ bridge.notifyLayout();
+ expect(messages).toHaveLength(1);
+ expect(messages[0]).toEqual({
+ source: "dbx-host",
+ version: 1,
+ type: "layout",
+ });
+
+ const posted: unknown[] = [];
+ const sdk = loadSdk(posted);
+ let sdkListenerFired = false;
+
+ sdk.dbxPlugin!.onLayout(() => {
+ sdkListenerFired = true;
+ });
+
+ sdk.receiveHostMessage(messages[0]);
+
+ expect(sdk.dispatchEvent).toHaveBeenCalledWith(expect.objectContaining({ type: "resize" }));
+ expect(sdk.document.dispatchEvent).toHaveBeenCalledWith(expect.objectContaining({ type: "dbx-plugin-layout" }));
+ expect(sdkListenerFired).toBe(true);
+ });
});
describe("AI completion bridge", () => {
diff --git a/apps/desktop/src/lib/plugins/pluginHostBridge.ts b/apps/desktop/src/lib/plugins/pluginHostBridge.ts
index 20e5cb40d7..c71fe279de 100644
--- a/apps/desktop/src/lib/plugins/pluginHostBridge.ts
+++ b/apps/desktop/src/lib/plugins/pluginHostBridge.ts
@@ -635,6 +635,15 @@ export class PluginHostBridge {
});
}
+ /** Tell the plugin UI that its workbench container was resized or transitioned to active. */
+ notifyLayout(): void {
+ this.post({
+ source: HOST_MESSAGE_SOURCE,
+ version: BRIDGE_VERSION,
+ type: "layout",
+ });
+ }
+
private async handleRequest(request: PluginRequestMessage, target: Window): Promise<void> {
try {
enforcePayloadLimit(request.params);
@@ -1316,7 +1325,7 @@ export function pluginSdkSource(initialTheme?: PluginBridgeTheme): string {
.replace(/\u2029/g, "\\u2029");
return `(() => {
const pending = new Map();
- const listeners = { event: new Set(), binary: new Set(), init: new Set(), context: new Set(), filedrop: new Set(), dragstate: new Set(), close: new Set() };
+ const listeners = { event: new Set(), binary: new Set(), init: new Set(), context: new Set(), filedrop: new Set(), dragstate: new Set(), close: new Set(), layout: new Set() };
let sequence = 0;
let contributionId;
let context;
@@ -1568,6 +1577,7 @@ export function pluginSdkSource(initialTheme?: PluginBridgeTheme): string {
onBinary: (listener) => { listeners.binary.add(listener); return () => listeners.binary.delete(listener); },
onContext: (listener) => { listeners.context.add(listener); return () => listeners.context.delete(listener); },
onInit: (listener) => { listeners.init.add(listener); if (context !== undefined) listener(context); return () => listeners.init.delete(listener); },
+ onLayout: (listener) => { listeners.layout.add(listener); return () => listeners.layout.delete(listener); },
// §8.3 workbench/close handshake: the host sends workbench/close before
// tearing the webview down; the plugin releases its workbench scope (PTY
// sessions, subscriptions) in the listeners and the SDK acks once every
@@ -1637,6 +1647,12 @@ export function pluginSdkSource(initialTheme?: PluginBridgeTheme): string {
: undefined;
listeners.dragstate.forEach((listener) => listener(active, position));
document.dispatchEvent(new CustomEvent('dbx-plugin-dragstate', { detail: active }));
+ } else if (message.type === 'layout') {
+ try {
+ window.dispatchEvent(new Event('resize'));
+ } catch {}
+ listeners.layout.forEach((listener) => listener(message));
+ document.dispatchEvent(new CustomEvent('dbx-plugin-layout', { detail: message }));
} else if (message.type === 'workbench/close') {
const notifyClose = (listener) => Promise.resolve().then(listener).catch(() => undefined);
Promise.allSettled([...listeners.close].map(notifyClose)).finally(() => {