mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-14 01:20:03 +00:00
## Summary Automatically clears transient validation errors (`value_bigger_than_max`, `value_smaller_than_min`, `value_not_in_list`, `required_input_missing`) when the user modifies a widget value or connects an input slot, so resolved errors don't linger in the error panel. Also clears missing model state when the user changes a combo widget value. ## Changes - **`useNodeErrorAutoResolve` composable**: watches widget changes and slot connections, clears matching errors via `executionErrorStore` - **`executionErrorStore`**: adds `clearSimpleNodeErrors` and `clearSimpleWidgetErrorIfValid` with granular per-slot error removal - **`executionErrorUtil`**: adds `isValueStillOutOfRange` to prevent premature clearing when a new value still violates the constraint - **`graphTraversalUtil`**: adds `getExecutionIdFromNodeData` for subgraph-aware execution ID resolution - **`GraphCanvas.vue`**: fixes subgraph error key lookup by using `getExecutionIdByNode` instead of raw `node.id` - **`NodeWidgets.vue`**: wires up the new composable to the widget layer - **`missingModelStore`**: adds `removeMissingModelByWidget` to clear missing model state on widget value change - **`useGraphNodeManager`**: registers composable per node - **Tests**: 126 new unit tests covering error clearing, range validation, and graph traversal edge cases ## Screenshots https://github.com/user-attachments/assets/515ea811-ff84-482a-a866-a17e5c779c39 https://github.com/user-attachments/assets/a2b30f02-4929-4537-952c-a0febe20f02e ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-9464-feat-auto-resolve-simple-validation-errors-on-widget-change-and-slot-connection-31b6d73d3650816b8afdc34f4b40295a) by [Unito](https://www.unito.io) --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
365 lines
12 KiB
Vue
365 lines
12 KiB
Vue
<template>
|
|
<div v-if="renderError" class="node-error p-2 text-sm text-red-500">
|
|
{{ st('nodeErrors.widgets', 'Node Widgets Error') }}
|
|
</div>
|
|
<div
|
|
v-else
|
|
:class="
|
|
cn(
|
|
'lg-node-widgets grid grid-cols-[min-content_minmax(80px,min-content)_minmax(125px,1fr)] gap-y-1 pr-3',
|
|
shouldHandleNodePointerEvents
|
|
? 'pointer-events-auto'
|
|
: 'pointer-events-none'
|
|
)
|
|
"
|
|
:style="{
|
|
'grid-template-rows': gridTemplateRows,
|
|
flex: gridTemplateRows.includes('auto') ? 1 : undefined
|
|
}"
|
|
@pointerdown.capture="handleBringToFront"
|
|
@pointerdown="handleWidgetPointerEvent"
|
|
@pointermove="handleWidgetPointerEvent"
|
|
@pointerup="handleWidgetPointerEvent"
|
|
>
|
|
<template
|
|
v-for="(widget, index) in processedWidgets"
|
|
:key="`widget-${index}-${widget.name}`"
|
|
>
|
|
<div
|
|
v-if="!widget.hidden && (!widget.advanced || showAdvanced)"
|
|
class="lg-node-widget group col-span-full grid grid-cols-subgrid items-stretch"
|
|
>
|
|
<!-- Widget Input Slot Dot -->
|
|
<div
|
|
:class="
|
|
cn(
|
|
'z-10 flex w-3 items-stretch opacity-0 transition-opacity duration-150 group-hover:opacity-100',
|
|
widget.slotMetadata?.linked && 'opacity-100'
|
|
)
|
|
"
|
|
>
|
|
<InputSlot
|
|
v-if="widget.slotMetadata"
|
|
:slot-data="{
|
|
name: widget.name,
|
|
type: widget.type,
|
|
boundingRect: [0, 0, 0, 0]
|
|
}"
|
|
:node-id="nodeData?.id != null ? String(nodeData.id) : ''"
|
|
:has-error="widget.hasError"
|
|
:index="widget.slotMetadata.index"
|
|
:socketless="widget.simplified.spec?.socketless"
|
|
dot-only
|
|
/>
|
|
</div>
|
|
<!-- Widget Component -->
|
|
<AppInput
|
|
:id="widget.id"
|
|
:name="widget.name"
|
|
:enable="canSelectInputs && !widget.simplified.options?.disabled"
|
|
>
|
|
<component
|
|
:is="widget.vueComponent"
|
|
v-model="widget.value"
|
|
v-tooltip.left="widget.tooltipConfig"
|
|
:widget="widget.simplified"
|
|
:node-id="nodeData?.id != null ? String(nodeData.id) : ''"
|
|
:node-type="nodeType"
|
|
:class="
|
|
cn(
|
|
'col-span-2',
|
|
widget.hasError && 'font-bold text-node-stroke-error'
|
|
)
|
|
"
|
|
@update:model-value="widget.updateHandler"
|
|
@contextmenu="widget.handleContextMenu"
|
|
/>
|
|
</AppInput>
|
|
</div>
|
|
</template>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import type { TooltipOptions } from 'primevue'
|
|
import { computed, onErrorCaptured, ref, toValue } from 'vue'
|
|
import type { Component } from 'vue'
|
|
|
|
import type {
|
|
SafeWidgetData,
|
|
VueNodeData,
|
|
WidgetSlotMetadata
|
|
} from '@/composables/graph/useGraphNodeManager'
|
|
import { useAppMode } from '@/composables/useAppMode'
|
|
import { showNodeOptions } from '@/composables/graph/useMoreOptionsMenu'
|
|
import { useErrorHandling } from '@/composables/useErrorHandling'
|
|
import { st } from '@/i18n'
|
|
import type { IWidgetOptions } from '@/lib/litegraph/src/types/widgets'
|
|
import { LGraphEventMode } from '@/lib/litegraph/src/types/globalEnums'
|
|
import { useSettingStore } from '@/platform/settings/settingStore'
|
|
import { useCanvasInteractions } from '@/renderer/core/canvas/useCanvasInteractions'
|
|
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
|
|
import AppInput from '@/renderer/extensions/linearMode/AppInput.vue'
|
|
import { useNodeTooltips } from '@/renderer/extensions/vueNodes/composables/useNodeTooltips'
|
|
import { useNodeEventHandlers } from '@/renderer/extensions/vueNodes/composables/useNodeEventHandlers'
|
|
import { useNodeZIndex } from '@/renderer/extensions/vueNodes/composables/useNodeZIndex'
|
|
import WidgetDOM from '@/renderer/extensions/vueNodes/widgets/components/WidgetDOM.vue'
|
|
// Import widget components directly
|
|
import WidgetLegacy from '@/renderer/extensions/vueNodes/widgets/components/WidgetLegacy.vue'
|
|
import {
|
|
getComponent,
|
|
shouldExpand,
|
|
shouldRenderAsVue
|
|
} from '@/renderer/extensions/vueNodes/widgets/registry/widgetRegistry'
|
|
import { nodeTypeValidForApp } from '@/stores/appModeStore'
|
|
import type { WidgetState } from '@/stores/widgetValueStore'
|
|
import {
|
|
stripGraphPrefix,
|
|
useWidgetValueStore
|
|
} from '@/stores/widgetValueStore'
|
|
import { usePromotionStore } from '@/stores/promotionStore'
|
|
import { useMissingModelStore } from '@/platform/missingModel/missingModelStore'
|
|
import { useExecutionErrorStore } from '@/stores/executionErrorStore'
|
|
import type { SimplifiedWidget, WidgetValue } from '@/types/simplifiedWidget'
|
|
import { cn } from '@/utils/tailwindUtil'
|
|
import { getExecutionIdFromNodeData } from '@/utils/graphTraversalUtil'
|
|
import { app } from '@/scripts/app'
|
|
|
|
import InputSlot from './InputSlot.vue'
|
|
|
|
interface NodeWidgetsProps {
|
|
nodeData?: VueNodeData
|
|
}
|
|
|
|
const { nodeData } = defineProps<NodeWidgetsProps>()
|
|
|
|
const { shouldHandleNodePointerEvents, forwardEventToCanvas } =
|
|
useCanvasInteractions()
|
|
const { isSelectInputsMode } = useAppMode()
|
|
const canvasStore = useCanvasStore()
|
|
const { bringNodeToFront } = useNodeZIndex()
|
|
const promotionStore = usePromotionStore()
|
|
const executionErrorStore = useExecutionErrorStore()
|
|
const missingModelStore = useMissingModelStore()
|
|
|
|
function handleWidgetPointerEvent(event: PointerEvent) {
|
|
if (shouldHandleNodePointerEvents.value) return
|
|
event.stopPropagation()
|
|
forwardEventToCanvas(event)
|
|
}
|
|
|
|
function handleBringToFront() {
|
|
if (nodeData?.id != null) {
|
|
bringNodeToFront(String(nodeData.id))
|
|
}
|
|
}
|
|
|
|
const { handleNodeRightClick } = useNodeEventHandlers()
|
|
|
|
// Error boundary implementation
|
|
const renderError = ref<string | null>(null)
|
|
|
|
const { toastErrorHandler } = useErrorHandling()
|
|
|
|
onErrorCaptured((error) => {
|
|
renderError.value = error.message
|
|
toastErrorHandler(error)
|
|
return false
|
|
})
|
|
|
|
const canSelectInputs = computed(
|
|
() =>
|
|
isSelectInputsMode.value &&
|
|
nodeData?.mode === LGraphEventMode.ALWAYS &&
|
|
nodeTypeValidForApp(nodeData.type) &&
|
|
!nodeData.hasErrors
|
|
)
|
|
const nodeType = computed(() => nodeData?.type || '')
|
|
const settingStore = useSettingStore()
|
|
const showAdvanced = computed(
|
|
() =>
|
|
nodeData?.showAdvanced ||
|
|
settingStore.get('Comfy.Node.AlwaysShowAdvancedWidgets')
|
|
)
|
|
const { getWidgetTooltip, createTooltipConfig } = useNodeTooltips(
|
|
nodeType.value
|
|
)
|
|
const widgetValueStore = useWidgetValueStore()
|
|
|
|
function createWidgetUpdateHandler(
|
|
widgetState: WidgetState | undefined,
|
|
widget: SafeWidgetData,
|
|
nodeExecId: string,
|
|
widgetOptions: IWidgetOptions | Record<string, never>
|
|
): (newValue: WidgetValue) => void {
|
|
return (newValue: WidgetValue) => {
|
|
if (widgetState) widgetState.value = newValue
|
|
widget.callback?.(newValue)
|
|
const effectiveExecId = widget.sourceExecutionId ?? nodeExecId
|
|
executionErrorStore.clearWidgetRelatedErrors(
|
|
effectiveExecId,
|
|
widget.slotName ?? widget.name,
|
|
widget.name,
|
|
newValue,
|
|
{ min: widgetOptions?.min, max: widgetOptions?.max }
|
|
)
|
|
}
|
|
}
|
|
|
|
interface ProcessedWidget {
|
|
advanced: boolean
|
|
handleContextMenu: (e: PointerEvent) => void
|
|
hasLayoutSize: boolean
|
|
hasError: boolean
|
|
hidden: boolean
|
|
id: string
|
|
name: string
|
|
simplified: SimplifiedWidget
|
|
tooltipConfig: TooltipOptions
|
|
type: string
|
|
updateHandler: (value: WidgetValue) => void
|
|
value: WidgetValue
|
|
vueComponent: Component
|
|
slotMetadata?: WidgetSlotMetadata
|
|
}
|
|
|
|
function hasWidgetError(
|
|
widget: SafeWidgetData,
|
|
nodeExecId: string,
|
|
nodeErrors: { errors: { extra_info?: { input_name?: string } }[] } | undefined
|
|
): boolean {
|
|
const errors = widget.sourceExecutionId
|
|
? executionErrorStore.lastNodeErrors?.[widget.sourceExecutionId]?.errors
|
|
: nodeErrors?.errors
|
|
const inputName = widget.slotName ?? widget.name
|
|
return (
|
|
!!errors?.some((e) => e.extra_info?.input_name === inputName) ||
|
|
missingModelStore.isWidgetMissingModel(
|
|
widget.sourceExecutionId ?? nodeExecId,
|
|
widget.name
|
|
)
|
|
)
|
|
}
|
|
|
|
const processedWidgets = computed((): ProcessedWidget[] => {
|
|
if (!nodeData?.widgets) return []
|
|
|
|
// nodeData.id is the local node ID; subgraph nodes need the full execution
|
|
// path (e.g. "65:63") to match keys in lastNodeErrors.
|
|
const nodeExecId = app.rootGraph
|
|
? getExecutionIdFromNodeData(app.rootGraph, nodeData)
|
|
: String(nodeData.id ?? '')
|
|
|
|
const nodeErrors = executionErrorStore.lastNodeErrors?.[nodeExecId]
|
|
const graphId = canvasStore.canvas?.graph?.rootGraph.id
|
|
|
|
const nodeId = nodeData.id
|
|
const { widgets } = nodeData
|
|
const result: ProcessedWidget[] = []
|
|
|
|
for (const widget of widgets) {
|
|
if (!shouldRenderAsVue(widget)) continue
|
|
|
|
const isPromotedView = !!widget.nodeId
|
|
|
|
const vueComponent =
|
|
getComponent(widget.type) ||
|
|
(widget.isDOMWidget ? WidgetDOM : WidgetLegacy)
|
|
|
|
const { slotMetadata } = widget
|
|
|
|
// Get metadata from store (registered during BaseWidget.setNodeId)
|
|
const bareWidgetId = stripGraphPrefix(
|
|
widget.storeNodeId ?? widget.nodeId ?? nodeId
|
|
)
|
|
const storeWidgetName = widget.storeName ?? widget.name
|
|
const widgetState = graphId
|
|
? widgetValueStore.getWidget(graphId, bareWidgetId, storeWidgetName)
|
|
: undefined
|
|
|
|
// Get value from store (falls back to undefined if not registered)
|
|
const value = widgetState?.value as WidgetValue
|
|
|
|
// Build options from store state, with disabled override for
|
|
// slot-linked widgets or widgets with disabled state (e.g. display-only)
|
|
const storeOptions = widgetState?.options ?? {}
|
|
const isDisabled = slotMetadata?.linked || widgetState?.disabled
|
|
const widgetOptions = isDisabled
|
|
? { ...storeOptions, disabled: true }
|
|
: storeOptions
|
|
|
|
const borderStyle =
|
|
graphId &&
|
|
!isPromotedView &&
|
|
promotionStore.isPromotedByAny(graphId, String(bareWidgetId), widget.name)
|
|
? 'ring ring-component-node-widget-promoted'
|
|
: widget.options?.advanced
|
|
? 'ring ring-component-node-widget-advanced'
|
|
: undefined
|
|
|
|
const simplified: SimplifiedWidget = {
|
|
name: widget.name,
|
|
type: widget.type,
|
|
value,
|
|
borderStyle,
|
|
callback: widget.callback,
|
|
controlWidget: widget.controlWidget,
|
|
label: widgetState?.label,
|
|
options: widgetOptions,
|
|
spec: widget.spec
|
|
}
|
|
|
|
const updateHandler = createWidgetUpdateHandler(
|
|
widgetState,
|
|
widget,
|
|
nodeExecId,
|
|
widgetOptions
|
|
)
|
|
|
|
const tooltipText = getWidgetTooltip(widget)
|
|
const tooltipConfig = createTooltipConfig(tooltipText)
|
|
const handleContextMenu = (e: PointerEvent) => {
|
|
e.preventDefault()
|
|
e.stopPropagation()
|
|
handleNodeRightClick(e, nodeId)
|
|
showNodeOptions(
|
|
e,
|
|
widget.name,
|
|
widget.nodeId !== undefined
|
|
? String(stripGraphPrefix(widget.nodeId))
|
|
: undefined
|
|
)
|
|
}
|
|
|
|
result.push({
|
|
advanced: widget.options?.advanced ?? false,
|
|
handleContextMenu,
|
|
hasLayoutSize: widget.hasLayoutSize ?? false,
|
|
hasError: hasWidgetError(widget, nodeExecId, nodeErrors),
|
|
hidden: widget.options?.hidden ?? false,
|
|
id: String(bareWidgetId),
|
|
name: widget.name,
|
|
type: widget.type,
|
|
vueComponent,
|
|
simplified,
|
|
value,
|
|
updateHandler,
|
|
tooltipConfig,
|
|
slotMetadata
|
|
})
|
|
}
|
|
|
|
return result
|
|
})
|
|
|
|
const gridTemplateRows = computed((): string => {
|
|
// Use processedWidgets directly since it already has store-based hidden/advanced
|
|
return toValue(processedWidgets)
|
|
.filter((w) => !w.hidden && (!w.advanced || showAdvanced.value))
|
|
.map((w) =>
|
|
shouldExpand(w.type) || w.hasLayoutSize ? 'auto' : 'min-content'
|
|
)
|
|
.join(' ')
|
|
})
|
|
</script>
|