mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-20 14:30:41 +00:00
## Summary Fix four bugs in the subgraph promoted widget panel where linked promotions were not distinguished from independent ones, causing incorrect UI state in both the SubgraphEditor (Settings) panel and the Parameters tab WidgetActions menu. ## Changes - **What**: Add `isLinkedPromotion` helper to correctly identify widgets driven by subgraph input connections. Fix `disambiguatingSourceNodeId` lookup mismatch that broke `isWidgetShownOnParents` and `handleHideInput` for non-nested promoted widgets. Replace fragile CSS icon selectors with `data-testid` attributes. ## Bugs fixed Companion fix PR for #10502 (red-green test PR). All 4 E2E tests from #10502 now pass: | Bug | Root cause | Fix | |-----|-----------|-----| | Linked promoted widgets have hide toggle enabled | `SubgraphEditor` only checked `node.id === -1` (physical) — linked promotions from subgraph input connections were not detected | Added `isLinkedPromotion` helper that checks `input._widget` bindings; `SubgraphNodeWidget` `:is-physical` prop now covers both physical and linked cases | | Linked promoted widgets show eye icon instead of link icon | Same root cause as above — `isPhysical` prop was only true for `node.id === -1` | Extended the `:is-physical` condition to include `isLinkedPromotion` check | | Widget labels show raw names instead of renamed values | `SubgraphEditor` passed `widget.name` instead of `widget.label \|\| widget.name` | Changed `:widget-name` binding to prefer `widget.label` | | WidgetActions menu shows Hide/Show for linked promotions | `v-if="hasParents"` didn't exclude linked promotions | Added `canToggleVisibility` computed that combines `hasParents` with `!isLinked` check via `isLinkedPromotion` | ### Additional bugs discovered and fixed | Bug | Root cause | Fix | |-----|-----------|-----| | "Show input" always displayed instead of "Hide input" for promoted widgets | `SectionWidgets.isWidgetShownOnParents` used `getSourceNodeId(widget)` which falls back to `widget.sourceNodeId` when `disambiguatingSourceNodeId` is undefined — this mismatches the promotion store key (`undefined`) | Changed to `widget.disambiguatingSourceNodeId` directly | | "Hide input" click does nothing | `WidgetActions.handleHideInput` used `getSourceNodeId(widget)` for the same reason — `demote()` couldn't find the entry to remove | Same fix — use `widget.disambiguatingSourceNodeId` directly | ## Tests added ### E2E (Playwright) — `browser_tests/tests/subgraphPromotedWidgetPanel.spec.ts` | Test | What it verifies | |------|-----------------| | linked promoted widgets have hide toggle disabled | All toggle buttons in SubgraphEditor shown section are disabled for linked widgets (covers 1-level and 2-level nested promotions via `subgraph-nested-promotion` fixture) | | linked promoted widgets show link icon instead of eye icon | Link icons appear for linked widgets, no eye icons present | | widget labels display renamed values instead of raw names | `widget.label` is displayed when set, not `widget.name` | | linked promoted widget menu should not show Hide/Show input | Three-dot menu on Parameters tab omits Hide/Show options for linked promotions, Rename is still available | ### Unit (Vitest) — `src/core/graph/subgraph/promotionUtils.test.ts` 7 tests covering `isLinkedPromotion`: basic matching, negative cases, nested subgraph with `disambiguatingSourceNodeId`, multiple inputs, and mixed linked/independent state. ### Unit (Vitest) — `src/components/rightSidePanel/parameters/WidgetActions.test.ts` - Added `isSubgraphNode: () => false` to mock nodes to prevent crash from new `isLinked` computed ## Review Focus - `isLinkedPromotion` reads `input._widget` (WeakRef-backed, non-reactive) directly in the template. This is intentional — `_widget` bindings are set during subgraph initialization before the user opens the panel, so stale reads don't occur in practice. A computed-based approach was attempted but reverted because `_widget` changes cannot trigger Vue reactivity. - `getSourceNodeId` removal in `SectionWidgets` and `WidgetActions` is intentional — the old fallback (`?? widget.sourceNodeId`) caused key mismatches with the promotion store for non-nested widgets. ## Screenshots Before <img width="723" height="935" alt="image" src="https://github.com/user-attachments/assets/09862578-a0d1-45b4-929c-f22f7494ebe2" /> After <img width="999" height="952" alt="image" src="https://github.com/user-attachments/assets/ed8fe604-6b44-46b9-a315-6da31d6b405a" />
294 lines
9.2 KiB
Vue
294 lines
9.2 KiB
Vue
<script setup lang="ts">
|
|
import { computed, inject, provide, ref, shallowRef, watchEffect } from 'vue'
|
|
import { useI18n } from 'vue-i18n'
|
|
|
|
import Button from '@/components/ui/button/Button.vue'
|
|
import { isPromotedWidgetView } from '@/core/graph/subgraph/promotedWidgetTypes'
|
|
import type { LGraphGroup, LGraphNode } from '@/lib/litegraph/src/litegraph'
|
|
import { SubgraphNode } from '@/lib/litegraph/src/litegraph'
|
|
import { usePromotionStore } from '@/stores/promotionStore'
|
|
import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets'
|
|
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
|
|
import { useExecutionErrorStore } from '@/stores/executionErrorStore'
|
|
import { useRightSidePanelStore } from '@/stores/workspace/rightSidePanelStore'
|
|
import { useSettingStore } from '@/platform/settings/settingStore'
|
|
import { cn } from '@/utils/tailwindUtil'
|
|
import { isGroupNode } from '@/utils/executableGroupNodeDto'
|
|
import { useNodeDefStore } from '@/stores/nodeDefStore'
|
|
import { getWidgetDefaultValue } from '@/utils/widgetUtil'
|
|
import type { WidgetValue } from '@/utils/widgetUtil'
|
|
|
|
import PropertiesAccordionItem from '../layout/PropertiesAccordionItem.vue'
|
|
import { HideLayoutFieldKey } from '@/types/widgetTypes'
|
|
|
|
import { GetNodeParentGroupKey } from '../shared'
|
|
import WidgetItem from './WidgetItem.vue'
|
|
import { getStableWidgetRenderKey } from '@/core/graph/subgraph/widgetRenderKey'
|
|
|
|
const {
|
|
label,
|
|
node,
|
|
widgets: widgetsProp,
|
|
showLocateButton = false,
|
|
isDraggable = false,
|
|
hiddenFavoriteIndicator = false,
|
|
showNodeName = false,
|
|
parents = [],
|
|
enableEmptyState = false,
|
|
tooltip
|
|
} = defineProps<{
|
|
label?: string
|
|
parents?: SubgraphNode[]
|
|
node?: LGraphNode
|
|
widgets: { widget: IBaseWidget; node: LGraphNode }[]
|
|
showLocateButton?: boolean
|
|
isDraggable?: boolean
|
|
hiddenFavoriteIndicator?: boolean
|
|
showNodeName?: boolean
|
|
/**
|
|
* Whether to show the empty state slot when there are no widgets.
|
|
*/
|
|
enableEmptyState?: boolean
|
|
tooltip?: string
|
|
}>()
|
|
|
|
const collapse = defineModel<boolean>('collapse', { default: false })
|
|
|
|
const widgetsContainer = ref<HTMLElement>()
|
|
const rootElement = ref<HTMLElement>()
|
|
|
|
const widgets = shallowRef(widgetsProp)
|
|
watchEffect(() => (widgets.value = widgetsProp))
|
|
|
|
provide(HideLayoutFieldKey, true)
|
|
|
|
const canvasStore = useCanvasStore()
|
|
const executionErrorStore = useExecutionErrorStore()
|
|
const rightSidePanelStore = useRightSidePanelStore()
|
|
const nodeDefStore = useNodeDefStore()
|
|
const { t } = useI18n()
|
|
|
|
const getNodeParentGroup = inject(GetNodeParentGroupKey, null)
|
|
|
|
const promotionStore = usePromotionStore()
|
|
|
|
function isWidgetShownOnParents(
|
|
widgetNode: LGraphNode,
|
|
widget: IBaseWidget
|
|
): boolean {
|
|
return parents.some((parent) => {
|
|
if (isPromotedWidgetView(widget)) {
|
|
const interiorNodeId =
|
|
String(widgetNode.id) === String(parent.id)
|
|
? widget.sourceNodeId
|
|
: String(widgetNode.id)
|
|
|
|
return promotionStore.isPromoted(parent.rootGraph.id, parent.id, {
|
|
sourceNodeId: interiorNodeId,
|
|
sourceWidgetName: widget.sourceWidgetName,
|
|
disambiguatingSourceNodeId: widget.disambiguatingSourceNodeId
|
|
})
|
|
}
|
|
return promotionStore.isPromoted(parent.rootGraph.id, parent.id, {
|
|
sourceNodeId: String(widgetNode.id),
|
|
sourceWidgetName: widget.name
|
|
})
|
|
})
|
|
}
|
|
|
|
const isEmpty = computed(() => widgets.value.length === 0)
|
|
|
|
const displayLabel = computed(
|
|
() => label ?? (node ? node.title : t('rightSidePanel.inputs'))
|
|
)
|
|
|
|
const targetNode = computed<LGraphNode | null>(() => {
|
|
if (node) return node
|
|
if (isEmpty.value) return null
|
|
|
|
const firstNodeId = widgets.value[0].node.id
|
|
const allSameNode = widgets.value.every(({ node }) => node.id === firstNodeId)
|
|
|
|
return allSameNode ? widgets.value[0].node : null
|
|
})
|
|
|
|
const hasDirectError = computed(() => {
|
|
if (!targetNode.value) return false
|
|
return executionErrorStore.activeGraphErrorNodeIds.has(
|
|
String(targetNode.value.id)
|
|
)
|
|
})
|
|
|
|
const hasContainerInternalError = computed(() => {
|
|
if (!targetNode.value) return false
|
|
const isContainer =
|
|
targetNode.value instanceof SubgraphNode || isGroupNode(targetNode.value)
|
|
if (!isContainer) return false
|
|
|
|
return executionErrorStore.isContainerWithInternalError(targetNode.value)
|
|
})
|
|
|
|
const nodeHasError = computed(() => {
|
|
if (!targetNode.value) return false
|
|
if (canvasStore.selectedItems.length === 1) return false
|
|
return hasDirectError.value || hasContainerInternalError.value
|
|
})
|
|
|
|
const showSeeError = computed(
|
|
() =>
|
|
nodeHasError.value &&
|
|
useSettingStore().get('Comfy.RightSidePanel.ShowErrorsTab')
|
|
)
|
|
|
|
const parentGroup = computed<LGraphGroup | null>(() => {
|
|
if (!targetNode.value || !getNodeParentGroup) return null
|
|
return getNodeParentGroup(targetNode.value)
|
|
})
|
|
|
|
const canShowLocateButton = computed(
|
|
() => showLocateButton && targetNode.value !== null
|
|
)
|
|
|
|
function handleLocateNode() {
|
|
if (!targetNode.value || !canvasStore.canvas) return
|
|
|
|
const graphNode = canvasStore.canvas.graph?.getNodeById(targetNode.value.id)
|
|
if (graphNode) {
|
|
canvasStore.canvas.animateToBounds(graphNode.boundingRect)
|
|
}
|
|
}
|
|
|
|
function navigateToErrorTab() {
|
|
if (!targetNode.value) return
|
|
if (!useSettingStore().get('Comfy.RightSidePanel.ShowErrorsTab')) return
|
|
rightSidePanelStore.focusedErrorNodeId = String(targetNode.value.id)
|
|
rightSidePanelStore.openPanel('errors')
|
|
}
|
|
|
|
function writeWidgetValue(widget: IBaseWidget, value: WidgetValue) {
|
|
widget.value = value
|
|
widget.callback?.(value)
|
|
canvasStore.canvas?.setDirty(true, true)
|
|
}
|
|
|
|
function handleResetAllWidgets() {
|
|
for (const { widget, node: widgetNode } of widgetsProp) {
|
|
const spec = nodeDefStore.getInputSpecForWidget(widgetNode, widget.name)
|
|
const defaultValue = getWidgetDefaultValue(spec)
|
|
if (defaultValue !== undefined) {
|
|
writeWidgetValue(widget, defaultValue)
|
|
}
|
|
}
|
|
}
|
|
|
|
function handleWidgetValueUpdate(widget: IBaseWidget, newValue: WidgetValue) {
|
|
if (newValue === undefined) return
|
|
writeWidgetValue(widget, newValue)
|
|
}
|
|
|
|
function handleWidgetReset(widget: IBaseWidget, newValue: WidgetValue) {
|
|
writeWidgetValue(widget, newValue)
|
|
}
|
|
|
|
defineExpose({
|
|
widgetsContainer,
|
|
rootElement
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<div ref="rootElement">
|
|
<PropertiesAccordionItem
|
|
v-model:collapse="collapse"
|
|
:enable-empty-state
|
|
:disabled="isEmpty"
|
|
:tooltip
|
|
:size="showSeeError ? 'lg' : 'default'"
|
|
>
|
|
<template #label>
|
|
<div class="flex min-w-0 flex-1 flex-wrap items-center gap-2">
|
|
<span class="flex min-w-0 flex-1 items-center gap-2">
|
|
<i
|
|
v-if="nodeHasError"
|
|
class="icon-[lucide--octagon-alert] size-4 shrink-0 text-destructive-background-hover"
|
|
/>
|
|
<span
|
|
:class="
|
|
cn(
|
|
'truncate',
|
|
nodeHasError && 'text-destructive-background-hover'
|
|
)
|
|
"
|
|
>
|
|
<slot name="label">
|
|
{{ displayLabel }}
|
|
</slot>
|
|
</span>
|
|
<span
|
|
v-if="parentGroup"
|
|
class="min-w-11 flex-1 truncate text-right text-xs text-muted-foreground"
|
|
:title="parentGroup.title"
|
|
>
|
|
{{ parentGroup.title }}
|
|
</span>
|
|
</span>
|
|
<Button
|
|
v-if="showSeeError"
|
|
variant="secondary"
|
|
size="sm"
|
|
class="h-8 shrink-0 rounded-lg text-sm"
|
|
@click.stop="navigateToErrorTab"
|
|
>
|
|
{{ t('rightSidePanel.seeError') }}
|
|
</Button>
|
|
<Button
|
|
v-if="!isEmpty"
|
|
variant="muted-textonly"
|
|
size="icon-sm"
|
|
class="subbutton size-8 shrink-0 hover:text-base-foreground"
|
|
:title="t('rightSidePanel.resetAllParameters')"
|
|
:aria-label="t('rightSidePanel.resetAllParameters')"
|
|
@click.stop="handleResetAllWidgets"
|
|
>
|
|
<i class="icon-[lucide--rotate-ccw] size-4" />
|
|
</Button>
|
|
<Button
|
|
v-if="canShowLocateButton"
|
|
variant="muted-textonly"
|
|
size="icon-sm"
|
|
class="subbutton mr-3 size-8 shrink-0 hover:text-base-foreground"
|
|
:title="t('rightSidePanel.locateNode')"
|
|
:aria-label="t('rightSidePanel.locateNode')"
|
|
@click.stop="handleLocateNode"
|
|
>
|
|
<i class="icon-[lucide--locate] size-4" />
|
|
</Button>
|
|
</div>
|
|
</template>
|
|
|
|
<template #empty><slot name="empty" /></template>
|
|
|
|
<div
|
|
ref="widgetsContainer"
|
|
class="relative space-y-2 rounded-lg px-4 pt-1"
|
|
>
|
|
<TransitionGroup name="list-scale">
|
|
<WidgetItem
|
|
v-for="{ widget, node } in widgets"
|
|
:key="getStableWidgetRenderKey(widget)"
|
|
:widget="widget"
|
|
:node="node"
|
|
:is-draggable="isDraggable"
|
|
:hidden-favorite-indicator="hiddenFavoriteIndicator"
|
|
:show-node-name="showNodeName"
|
|
:parents="parents"
|
|
:is-shown-on-parents="isWidgetShownOnParents(node, widget)"
|
|
@update:widget-value="handleWidgetValueUpdate(widget, $event)"
|
|
@reset-to-default="handleWidgetReset(widget, $event)"
|
|
/>
|
|
</TransitionGroup>
|
|
</div>
|
|
</PropertiesAccordionItem>
|
|
</div>
|
|
</template>
|