From fbae6b31775bb2d017deb8ac5723c429a72ff853 Mon Sep 17 00:00:00 2001 From: uytieu Date: Sun, 27 Sep 2026 03:01:25 +0000 Subject: [PATCH 1/3] fix(agent): keep the expanded agent panel inside the window (#18182) The agent panel kept its width when the window became narrower. An expanded panel went past the right edge of the window and out of sight. The panel now becomes narrower with the window, and it stops when it meets the sidebar. - **What**: - The width of the panel is now the result of two values. The first value is the width the user asked for. The second value is the space that the workspace to the left needs. - The panel becomes narrower when the window becomes narrower. The panel returns to the requested width when the window becomes wider again. The user does not lose the choice they made. - The workspace needs room for the side toolbar and for the sidebar. The panel stops at the sidebar. When no sidebar is open, the panel can use that room instead. - The maximize button read the panel width and compared it to a fixed number. A panel that the window made narrower failed that comparison, so the button showed the wrong icon. The button now reads explicit state. - The canvas toolbar at the bottom of the graph was anchored to the right edge. A toolbar wider than the canvas hung over the left edge and went behind the sidebar. The toolbar now stays inside the canvas. A toolbar with more buttons than the canvas holds scrolls sideways. - **The panel respects the minimum width of the sidebar, not the current width of the sidebar.** The sidebar is a percentage of the area beside the panel. If the panel reads the live width of the sidebar, the sidebar gets wider. A wider sidebar then makes the panel narrower again. This loop has no end. The minimum width breaks it. The effect is that a sidebar the user dragged wider still gives room back to the panel. - A window with less room than `PANEL_MIN_WIDTH` now gets a panel narrower than that minimum. A panel of 232px in a 600px window is poor, and a panel that leaves the window is worse. A window this narrow is below the desktop range. - `SIDE_TOOLBAR_WIDTH` is 56px. A measurement in the browser gave this number. It is the connected rail, which adds `--sidebar-padding` on each side of the 48px icons. My first value of 48px made the panel start 8px inside the rail. https://github.com/user-attachments/assets/e9a3554c-ac91-4de4-839f-5fb8a9469c7d Linear: [DES-1037](https://linear.app/comfyorg/issue/DES-1037/des-keep-expanded-agent-panel-within-window-bounds) --------- Co-authored-by: bymyself (cherry picked from commit ffdf25857654efb631781668e4a68d5bce1ecb60) --- .../tests/agent/agentPanelLifecycle.spec.ts | 91 +++++++++++ .../LiteGraphCanvasSplitterOverlay.test.ts | 41 +++++ .../LiteGraphCanvasSplitterOverlay.vue | 23 ++- src/components/graph/GraphCanvasMenu.vue | 150 +++++++++--------- src/constants/splitterConstants.ts | 9 ++ .../components/agent/DockedAgentPanel.test.ts | 10 +- .../stores/agent/agentPanelStore.test.ts | 150 +++++++++++++++++- .../agent/stores/agent/agentPanelStore.ts | 50 +++++- .../stores/agent/agentPanelStoreId.test.ts | 4 +- 9 files changed, 441 insertions(+), 87 deletions(-) diff --git a/browser_tests/tests/agent/agentPanelLifecycle.spec.ts b/browser_tests/tests/agent/agentPanelLifecycle.spec.ts index 0c885d29ad5..46cf4f252ad 100644 --- a/browser_tests/tests/agent/agentPanelLifecycle.spec.ts +++ b/browser_tests/tests/agent/agentPanelLifecycle.spec.ts @@ -127,6 +127,97 @@ test.describe( await expect(page.getByTestId('integrated-tab-bar-actions')).toBeVisible() }) + test('shrinks a maximized panel to stay inside a narrowed window', async ({ + page + }) => { + await page.setViewportSize({ width: 1600, height: 900 }) + await bootAgentApp(page, true) + + await page + .getByRole('button', { name: OPEN_AGENT_LABEL, exact: true }) + .click() + const panel = page.getByTestId('docked-agent-panel') + await expect(panel).toBeVisible() + + await panel + .getByRole('button', { name: enMessages.agent.maximize }) + .click() + await expect + .poll(async () => (await panel.boundingBox())?.width ?? 0) + .toBe(960) + + await page.setViewportSize({ width: 900, height: 900 }) + + await expect + .poll(async () => (await panel.boundingBox())?.width ?? 0) + .toBeLessThan(960) + const box = await panel.boundingBox() + expect(box).not.toBeNull() + expect(box!.x).toBeGreaterThanOrEqual(-1) + expect(box!.x + box!.width).toBeLessThanOrEqual(901) + + // "Inside the window" is not enough on its own: a panel that ignored the + // sidebar and took all 900px would satisfy every bound above. Pin it + // against the workspace it is supposed to be reserving room for. + const sideToolbar = page.getByTestId('side-toolbar') + const railBox = await sideToolbar.boundingBox() + expect(railBox).not.toBeNull() + expect(box!.x).toBeGreaterThanOrEqual(railBox!.x + railBox!.width - 1) + + // Still maximized, so the header offers to minimize rather than maximize. + await expect( + panel.getByRole('button', { name: enMessages.agent.minimize }) + ).toBeVisible() + }) + + test('keeps the canvas toolbar clear of the sidebar as the panel squeezes it', async ({ + page + }) => { + // 1300 puts the canvas at roughly 284px: narrower than the toolbar, so + // the overhang this fix prevents is actually in play, but not the + // degenerate case. At 900 a maximized panel leaves the canvas at zero + // and the toolbar collapses to 8px, which tests the unreserved-canvas + // gap rather than this fix. `agentPanelViewportDrag.spec.ts` owns that. + await page.setViewportSize({ width: 1300, height: 900 }) + await bootAgentApp(page, true) + + await page + .getByRole('button', { name: OPEN_AGENT_LABEL, exact: true }) + .click() + const panel = page.getByTestId('docked-agent-panel') + await expect(panel).toBeVisible() + await panel + .getByRole('button', { name: enMessages.agent.maximize }) + .click() + + const toolbar = page.getByRole('toolbar', { + name: enMessages.graphCanvasMenu.canvasToolbar + }) + const sideToolbar = page.getByTestId('side-toolbar') + await expect(toolbar).toBeVisible() + + const toolbarBox = await toolbar.boundingBox() + const sideToolbarBox = await sideToolbar.boundingBox() + expect(toolbarBox).not.toBeNull() + expect(sideToolbarBox).not.toBeNull() + + // Both edges matter. Checking only the left edge passes a toolbar that + // overhangs the other way, out from under the canvas and beneath the + // expanded panel, which is the case this fix is actually about. + expect(toolbarBox!.x).toBeGreaterThanOrEqual( + sideToolbarBox!.x + sideToolbarBox!.width - 1 + ) + // Position alone is satisfied by a toolbar squeezed to nothing, so prove + // the controls at both ends survived and are still operable. + expect(toolbarBox!.width).toBeGreaterThan(64) + await expect( + toolbar.getByRole('button', { name: enMessages.zoomControls.label }) + ).toBeVisible() + await toolbar + .getByRole('button', { name: enMessages.graphCanvasMenu.fitView }) + .click() + }) + test('restores an open panel after a browser reload', async ({ page }) => { await bootAgentApp(page, true) diff --git a/src/components/LiteGraphCanvasSplitterOverlay.test.ts b/src/components/LiteGraphCanvasSplitterOverlay.test.ts index 05160888df4..9bd7cb4d499 100644 --- a/src/components/LiteGraphCanvasSplitterOverlay.test.ts +++ b/src/components/LiteGraphCanvasSplitterOverlay.test.ts @@ -12,7 +12,12 @@ import { useSettingStore } from '@/platform/settings/settingStore' import { useAgentNodeSelectionStore } from '@/stores/agentNodeSelectionStore' import { useAgentPanelStore } from '@/workbench/extensions/agent/stores/agent/agentPanelStore' import { useBottomPanelStore } from '@/stores/workspace/bottomPanelStore' +import { useSidebarTabStore } from '@/stores/workspace/sidebarTabStore' +import type { SidebarTabExtension } from '@/types/extensionTypes' +// This branch stubs the auth store directly rather than mocking `firebase/auth` +// the way main does, so the incoming `vi.mock(import('firebase/auth'))` is +// dropped and the existing stub kept. vi.mock('@/stores/authStore', () => ({ useAuthStore: vi.fn(() => ({ currentUser: null, loading: false })) })) @@ -120,6 +125,42 @@ describe('LiteGraphCanvasSplitterOverlay', () => { expect(screen.getByTestId('topmenu')).toBeInTheDocument() }) + it('reserves room for the sidebar so the Agent panel stops before it', async () => { + const agentPanelStore = useAgentPanelStore() + const sidebarTabStore = useSidebarTabStore() + const i18n = createI18n({ + legacy: false, + locale: 'en', + messages: { en: { sideToolbar: { sidebar: 'Sidebar' } } } + }) + + render(LiteGraphCanvasSplitterOverlay, { + global: { + plugins: [getActivePinia()!, i18n], + stubs: { Splitter: true, SplitterPanel: true } + } + }) + + window.innerWidth = 1200 + window.dispatchEvent(new Event('resize')) + agentPanelStore.toggleMaximize() + await nextTick() + const widthWithoutSidebar = agentPanelStore.width + + sidebarTabStore.sidebarTabs = [ + { id: 'probe', title: 'Probe' } as SidebarTabExtension + ] + sidebarTabStore.activeSidebarTabId = 'probe' + await nextTick() + + expect(agentPanelStore.width).toBeLessThan(widthWithoutSidebar) + + sidebarTabStore.activeSidebarTabId = null + await nextTick() + + expect(agentPanelStore.width).toBe(widthWithoutSidebar) + }) + it('refreshes the splitter only when the Agent panel becomes visible', async () => { const agentPanelStore = useAgentPanelStore() agentPanelStore.enabled = true diff --git a/src/components/LiteGraphCanvasSplitterOverlay.vue b/src/components/LiteGraphCanvasSplitterOverlay.vue index cb7c834aa47..2f4a661e80d 100644 --- a/src/components/LiteGraphCanvasSplitterOverlay.vue +++ b/src/components/LiteGraphCanvasSplitterOverlay.vue @@ -150,7 +150,7 @@ import { storeToRefs } from 'pinia' import Splitter from 'primevue/splitter' import type { SplitterResizeStartEvent } from 'primevue/splitter' import SplitterPanel from 'primevue/splitterpanel' -import { computed } from 'vue' +import { computed, watchEffect } from 'vue' import { useI18n } from 'vue-i18n' import { useAppMode } from '@/composables/useAppMode' @@ -158,7 +158,9 @@ import { BUILDER_MIN_SIZE, CENTER_PANEL_SIZE, SIDEBAR_MIN_SIZE, - SIDE_PANEL_SIZE + SIDEBAR_MIN_WIDTH, + SIDE_PANEL_SIZE, + SIDE_TOOLBAR_WIDTH } from '@/constants/splitterConstants' import { useSettingStore } from '@/platform/settings/settingStore' import { useAgentNodeSelectionStore } from '@/stores/agentNodeSelectionStore' @@ -223,6 +225,23 @@ const sidebarPanelVisible = computed( () => activeSidebarTab.value !== null && !isBuilderMode.value ) +/** + * The sidebar can never be squeezed past `min-w-78`, so it and the toolbar + * rail are the floor the agent panel has to respect. Feeding the floor rather + * than the sidebar's live width keeps this one-way: a panel that shrank would + * otherwise widen the sidebar and shrink itself again. + */ +watchEffect(() => { + agentPanelStore.setReservedWorkspaceWidth( + SIDE_TOOLBAR_WIDTH + + (sidebarPanelVisible.value && + !focusMode.value && + !agentNodeSelectionActive.value + ? SIDEBAR_MIN_WIDTH + : 0) + ) +}) + const firstPanelVisible = computed( () => sidebarLocation.value === 'left' || showOffsideSplitter.value ) diff --git a/src/components/graph/GraphCanvasMenu.vue b/src/components/graph/GraphCanvasMenu.vue index 94bcb71e722..53e7acea596 100644 --- a/src/components/graph/GraphCanvasMenu.vue +++ b/src/components/graph/GraphCanvasMenu.vue @@ -9,80 +9,86 @@ @click="hideModal" > - - - -
- -