mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-05 05:32:02 +00:00
#8625 fixed a bug where `ProgressTextWidget`s would be serialized to workflow data and, under rare circumstances, clobber over other widget values on restore. I was mistaken that the `serialize: false` being sent to options does serve a purpose: preventing the widget value from being serialized to the (api) prompt which is sent to the backend. This PR reverts the removal so now both forms of disabling serialization apply. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-9221-Prevent-serialization-of-progress-text-to-prompt-3126d73d365081c5b9ecc560f0a248d5) by [Unito](https://www.unito.io)
70 lines
2.1 KiB
TypeScript
70 lines
2.1 KiB
TypeScript
import TextPreviewWidget from '@/components/graph/widgets/TextPreviewWidget.vue'
|
|
import { resolveNodeRootGraphId } from '@/lib/litegraph/src/litegraph'
|
|
import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
|
|
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
|
|
import { ComponentWidgetImpl, addWidget } from '@/scripts/domWidget'
|
|
import type { ComponentWidgetStandardProps } from '@/scripts/domWidget'
|
|
import { app } from '@/scripts/app'
|
|
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
|
|
import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets'
|
|
import { useWidgetValueStore } from '@/stores/widgetValueStore'
|
|
|
|
type TextPreviewCustomProps = Omit<
|
|
InstanceType<typeof TextPreviewWidget>['$props'],
|
|
ComponentWidgetStandardProps
|
|
>
|
|
|
|
const PADDING = 16
|
|
|
|
export function useTextPreviewWidget(
|
|
options: {
|
|
minHeight?: number
|
|
} = {}
|
|
): ComfyWidgetConstructorV2 {
|
|
function widgetConstructor(
|
|
node: LGraphNode,
|
|
inputSpec: InputSpec
|
|
): IBaseWidget {
|
|
const widget = new ComponentWidgetImpl<
|
|
string | object,
|
|
TextPreviewCustomProps
|
|
>({
|
|
node,
|
|
name: inputSpec.name,
|
|
component: TextPreviewWidget,
|
|
inputSpec,
|
|
props: {
|
|
nodeId: node.id
|
|
},
|
|
options: {
|
|
getValue: () =>
|
|
useWidgetValueStore().getWidget(
|
|
resolveNodeRootGraphId(node, app.rootGraph.id),
|
|
node.id,
|
|
inputSpec.name
|
|
)?.value ?? '',
|
|
setValue: (value: string | object) => {
|
|
const graphId = resolveNodeRootGraphId(node, app.rootGraph.id)
|
|
const widgetState = useWidgetValueStore().getWidget(
|
|
graphId,
|
|
node.id,
|
|
inputSpec.name
|
|
)
|
|
if (widgetState)
|
|
widgetState.value =
|
|
typeof value === 'string' ? value : String(value)
|
|
},
|
|
getMinHeight: () => options.minHeight ?? 42 + PADDING,
|
|
serialize: false,
|
|
read_only: true
|
|
},
|
|
type: inputSpec.type
|
|
})
|
|
widget.serialize = false
|
|
addWidget(node, widget)
|
|
return widget
|
|
}
|
|
|
|
return widgetConstructor
|
|
}
|