From a9892d1c32bd2c5b5b925535eaf3ab1896c4cf6a Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Thu, 15 Oct 2026 22:25:49 +0000 Subject: [PATCH] fix: size legacy widget canvases from layout width, not zoomed rect (FE-3459) (#21114) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit *PR Created by the Glary-Bot Agent* --- ## Summary Fixes [FE-3459](https://linear.app/comfyorg/issue/FE-3459): in Nodes 2.0, the widgets on VHS **Load Video (Upload)** overlap each other. In `WidgetLegacy.vue` `draw()`, #15453 ("test: cover direct widget array mutations", which landed on main through the ECS migration #14246) changed the order of the two canvas width sources. `getBoundingClientRect().width` now came first and `parentElement.clientWidth` became the fallback. - `getBoundingClientRect()` includes the graph canvas zoom transform. A legacy widget redrawn while the graph is zoomed out was therefore sized at the scaled width. That width was used for `computeSize`/height, `widget.width` and the canvas backing width, so the widget heights came out wrong. - A transform change doesn't trigger `ResizeObserver`, so the wrong size stayed after zooming back to 100%. The result was overlapping widgets. This PR puts the two lines back in their original order. Layout `clientWidth` (not affected by the transform) comes first, and the bounding rect is only the fallback for the zero-width case. The parent is still `w-full`, so `clientWidth` and the rect agree at 1× zoom. ## Changes - `WidgetLegacy.vue`: `parentElement.clientWidth || getBoundingClientRect().width` - `WidgetLegacy.test.ts`: new regression test. It mocks a layout width of 200 and a zoomed rect width of 100, then checks that `widget.width` is 200 and the canvas backing width is 400. I confirmed the test fails without the fix (`expected 100 to be 200`). ## Verification - `pnpm vitest run src/renderer/extensions/vueNodes/widgets/components/`: 497/497 pass - `pnpm typecheck`, oxlint, eslint, oxfmt: clean - Browser check (done in the FE-3459 investigation, not repeated here): production builds served by ComfyUI with the real VideoHelperSuite extension showed the overlap. Swapping only these two lines fixed it, both on the commit that introduced the overlap and on current `main`. I didn't take a separate Playwright screenshot for this PR, because the repro needs the VHS custom node plus an uploaded video in a backend. Linear: FE-3459 Co-authored-by: Glary-Bot --- .../widgets/components/WidgetLegacy.test.ts | 39 +++++++++++++++++++ .../widgets/components/WidgetLegacy.vue | 4 +- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/renderer/extensions/vueNodes/widgets/components/WidgetLegacy.test.ts b/src/renderer/extensions/vueNodes/widgets/components/WidgetLegacy.test.ts index 3f931d4d13f..6f7fffa61b0 100644 --- a/src/renderer/extensions/vueNodes/widgets/components/WidgetLegacy.test.ts +++ b/src/renderer/extensions/vueNodes/widgets/components/WidgetLegacy.test.ts @@ -97,3 +97,42 @@ describe('WidgetLegacy canvas sizing', () => { } ) }) + +describe('WidgetLegacy canvas width', () => { + it('uses the untransformed layout width when the canvas is zoomed', async () => { + const graph = new LGraph() + const node = new LGraphNode('Legacy') + const widget = node.addWidget('number', 'frame_load_cap', 0, () => {}) + graph.add(node) + widget.draw = () => {} + useCanvasStore().canvas = fromPartial({ graph }) + await nextTick() + + const layoutWidth = 200 + const zoomedRectWidth = layoutWidth * 0.5 + vi.spyOn(HTMLElement.prototype, 'clientWidth', 'get').mockReturnValue( + layoutWidth + ) + vi.spyOn( + HTMLCanvasElement.prototype, + 'getBoundingClientRect' + ).mockReturnValue(DOMRect.fromRect({ width: zoomedRectWidth, height: 20 })) + const canvases: HTMLCanvasElement[] = [] + vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockImplementation( + function (this: HTMLCanvasElement) { + canvases.push(this) + return null + } + ) + + render(WidgetLegacy, { + props: { + nodeId: node.id, + widget: { name: 'frame_load_cap', type: 'number', value: undefined } + } + }) + + expect(widget.width).toBe(layoutWidth) + expect(canvases.at(-1)?.width).toBe(layoutWidth * 2) + }) +}) diff --git a/src/renderer/extensions/vueNodes/widgets/components/WidgetLegacy.vue b/src/renderer/extensions/vueNodes/widgets/components/WidgetLegacy.vue index 78758ba93b8..3ca87441517 100644 --- a/src/renderer/extensions/vueNodes/widgets/components/WidgetLegacy.vue +++ b/src/renderer/extensions/vueNodes/widgets/components/WidgetLegacy.vue @@ -93,8 +93,8 @@ function getWidgetHeight( function draw() { if (!widgetInstance || !node) return const width = - canvasEl.value.getBoundingClientRect().width || - canvasEl.value.parentElement.clientWidth + canvasEl.value.parentElement.clientWidth || + canvasEl.value.getBoundingClientRect().width const height = getWidgetHeight(widgetInstance, node, width) containerHeight.value = height node.canvasHeight = height