From 10e9bc2f8dc958b2afe80cced3d0d6e311f93b9b Mon Sep 17 00:00:00 2001 From: Terry Jia Date: Tue, 10 Feb 2026 20:47:37 -0500 Subject: [PATCH] fix: extract WidgetCallbackOptions interface and add curly braces (#8791) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary improve for https://github.com/Comfy-Org/ComfyUI_frontend/pull/8774 ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-8791-fix-extract-WidgetCallbackOptions-interface-and-add-curly-braces-3046d73d365081c49e37c0a2596f1958) by [Unito](https://www.unito.io) --- src/scripts/app.ts | 3 ++- src/types/litegraph-augmentation.d.ts | 8 ++++++-- src/utils/litegraphUtil.ts | 5 +++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/scripts/app.ts b/src/scripts/app.ts index 8b154fd87..b38b7ac53 100644 --- a/src/scripts/app.ts +++ b/src/scripts/app.ts @@ -1394,8 +1394,9 @@ export class ComfyApp { // Allow widgets to run callbacks before a prompt has been queued // e.g. random seed before every gen forEachNode(this.rootGraph, (node) => { - for (const widget of node.widgets ?? []) + for (const widget of node.widgets ?? []) { widget.beforeQueued?.({ isPartialExecution }) + } }) const p = await this.graphToPrompt(this.rootGraph) diff --git a/src/types/litegraph-augmentation.d.ts b/src/types/litegraph-augmentation.d.ts index bdc71ce66..163e98ac5 100644 --- a/src/types/litegraph-augmentation.d.ts +++ b/src/types/litegraph-augmentation.d.ts @@ -45,10 +45,14 @@ declare module '@/lib/litegraph/src/types/widgets' { hidden?: boolean } + interface WidgetCallbackOptions { + isPartialExecution?: boolean + } + interface IBaseWidget { onRemove?(): void - beforeQueued?(options?: { isPartialExecution?: boolean }): unknown - afterQueued?(options?: { isPartialExecution?: boolean }): unknown + beforeQueued?(options?: WidgetCallbackOptions): unknown + afterQueued?(options?: WidgetCallbackOptions): unknown serializeValue?(node: LGraphNode, index: number): Promise | unknown /** diff --git a/src/utils/litegraphUtil.ts b/src/utils/litegraphUtil.ts index 0e96416fc..e47aab1d8 100644 --- a/src/utils/litegraphUtil.ts +++ b/src/utils/litegraphUtil.ts @@ -14,7 +14,8 @@ import type { } from '@/lib/litegraph/src/types/serialisation' import type { IBaseWidget, - IComboWidget + IComboWidget, + WidgetCallbackOptions } from '@/lib/litegraph/src/types/widgets' import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2' @@ -84,7 +85,7 @@ export const getItemsColorOption = (items: unknown[]): ColorOption | null => { export function executeWidgetsCallback( nodes: LGraphNode[], callbackName: 'onRemove' | 'beforeQueued' | 'afterQueued', - options?: { isPartialExecution?: boolean } + options?: WidgetCallbackOptions ) { for (const node of nodes) { for (const widget of node.widgets ?? []) {