From 197a6cbae82371c0132ea199a2571540360d3194 Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Wed, 9 Apr 2025 16:06:05 -0400 Subject: [PATCH] Add IBaseWidget.serialize flag (#915) https://github.com/Comfy-Org/ComfyUI_frontend/pull/3323 Some widgets are only used for display purpose (The preview image widget), their value shouldn't be serialized into the workflow. This PR adds a flag to allow widget to skip value serialization. --- src/LGraphNode.ts | 1 + src/types/widgets.ts | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/LGraphNode.ts b/src/LGraphNode.ts index 3432d756e4..6b06901ee1 100644 --- a/src/LGraphNode.ts +++ b/src/LGraphNode.ts @@ -777,6 +777,7 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { if (widgets && this.serialize_widgets) { o.widgets_values = [] for (const [i, widget] of widgets.entries()) { + if (widget.serialize === false) continue // @ts-expect-error #595 No-null o.widgets_values[i] = widget ? widget.value : null } diff --git a/src/types/widgets.ts b/src/types/widgets.ts index 0a9c36cd8c..669e71311a 100644 --- a/src/types/widgets.ts +++ b/src/types/widgets.ts @@ -150,6 +150,12 @@ export interface IBaseWidget { type: TWidgetType value?: TWidgetValue + /** + * Whether the widget value should be serialized on node serialization. + * @default true + */ + serialize?: boolean + /** * The computed height of the widget. Used by customized node resize logic. * See scripts/domWidget.ts for more details.