From e7863676dd04548465319657103315b66ae101bc Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Wed, 5 Mar 2025 16:59:16 -0500 Subject: [PATCH] [BugFix] Fire resize callback for all dom widgets under the same node (#2882) --- src/scripts/domWidget.ts | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/scripts/domWidget.ts b/src/scripts/domWidget.ts index be59be189..ae5435384 100644 --- a/src/scripts/domWidget.ts +++ b/src/scripts/domWidget.ts @@ -6,12 +6,10 @@ import type { IWidgetOptions } from '@comfyorg/litegraph/dist/types/widgets' +import { useChainCallback } from '@/composables/functional/useChainCallback' +import { app } from '@/scripts/app' import { useSettingStore } from '@/stores/settingStore' -import { app } from './app' - -const SIZE = Symbol() - interface Rect { height: number width: number @@ -66,6 +64,13 @@ export interface DOMWidgetOptions< getMaxHeight?: () => number getHeight?: () => string | number onDraw?: (widget: DOMWidget) => void + /** + * @deprecated Use `afterResize` instead. This callback is a legacy API + * that fires before resize happens, but it is no longer supported. Now it + * fires after resize happens. + * The resize logic has been upstreamed to litegraph in + * https://github.com/Comfy-Org/ComfyUI_frontend/pull/2557 + */ beforeResize?: (this: DOMWidget, node: LGraphNode) => void afterResize?: (this: DOMWidget, node: LGraphNode) => void } @@ -383,17 +388,10 @@ LGraphNode.prototype.addDOMWidget = function < onRemoved?.call(this) } - // @ts-ignore index with symbol - if (!this[SIZE]) { - // @ts-ignore index with symbol - this[SIZE] = true - const onResize = this.onResize - this.onResize = function (this: LGraphNode, size: Size) { - options.beforeResize?.call(widget, this) - onResize?.call(this, size) - options.afterResize?.call(widget, this) - } - } + this.onResize = useChainCallback(this.onResize, () => { + options.beforeResize?.call(widget, this) + options.afterResize?.call(widget, this) + }) return widget }