Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
3b8b1ba
feat: add slot context menu with rename for Vue nodes
christian-byrne Feb 21, 2026
e83a791
fix: guard renameSlot with canRenameSlot check
christian-byrne Mar 12, 2026
a15fc2e
fix: guard onSlotContextMenu to prevent empty menu popup
christian-byrne Mar 12, 2026
a036e45
fix: reject empty string in handleRename to prevent ghost labels
christian-byrne Mar 12, 2026
1f59eab
test: add comprehensive slot context menu tests (TDD red phase)
christian-byrne Mar 13, 2026
b39e14d
feat: rework slot context menu with full LiteGraph parity
christian-byrne Mar 13, 2026
5c8b813
test: add e2e tests for slot context menu in Vue nodes mode
christian-byrne Mar 13, 2026
9cba6b2
[automated] Apply ESLint and Oxfmt fixes
actions-user Mar 13, 2026
40a0ebc
fix: slot rename reactivity and align menu to design system
christian-byrne Mar 15, 2026
edfc90a
fix: preserve shallowReactive array identity in refreshNodeSlots
christian-byrne Mar 15, 2026
cfc10aa
feat: instrument slot label setter for reactive updates and add renam…
christian-byrne Mar 15, 2026
75a03cc
refactor: remove unused return values from useCanvasAnchoredPosition
christian-byrne Mar 17, 2026
835b084
refactor: rename useSlotContextMenu to slotMenuService
christian-byrne Mar 17, 2026
4f7e063
fix: improve SlotContextMenu accessibility and robustness
christian-byrne Mar 17, 2026
056466b
refactor: move SlotContextMenu to src/components/graph/
christian-byrne Mar 17, 2026
eda0853
test: use stable .slot-dot locators and node ID in e2e tests
christian-byrne Mar 17, 2026
7de8fb1
[automated] Apply ESLint and Oxfmt fixes
actions-user Mar 17, 2026
834aed3
fix: address playwright lint and import path violations in slot menu e2e
christian-byrne May 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
209 changes: 209 additions & 0 deletions browser_tests/tests/vueNodes/interactions/node/slotContextMenu.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
import { expect } from '@playwright/test'

import { comfyPageFixture as test } from '@e2e/fixtures/ComfyPage'

test.describe('Vue Nodes - Slot Context Menu', () => {
test.beforeEach(async ({ comfyPage }) => {
await comfyPage.settings.setSetting('Comfy.VueNodes.Enabled', true)
await comfyPage.settings.setSetting('Comfy.Graph.CanvasMenu', false)
await comfyPage.setup()
await comfyPage.vueNodes.waitForNodes()
})

test('Right-clicking an input slot dot shows the slot context menu', async ({
comfyPage
}) => {
// KSampler has input slots with connections — find any input slot
const ksamplerNode = comfyPage.vueNodes.getNodeByTitle('KSampler')
const inputSlot = ksamplerNode.locator('.lg-slot--input').first()
await expect(inputSlot).toBeVisible()

await inputSlot.locator('.slot-dot').click({ button: 'right' })

// The custom slot context menu should appear (role="menu" is on the
// teleported menu, not on the PrimeVue node context menu)
const slotMenu = comfyPage.page.locator(
'div[role="menu"]:not(.p-contextmenu)'
)
await expect(slotMenu).toBeVisible()

// Should show "Rename" since standard slots are not nameLocked
await expect(
slotMenu.getByRole('menuitem', { name: 'Rename' })
).toBeVisible()
})

test('Right-clicking the node body shows the node context menu, not the slot menu', async ({
comfyPage
}) => {
const ksamplerNode = comfyPage.vueNodes.getNodeByTitle('KSampler')
const nodeBody = ksamplerNode.locator('[data-testid^="node-body-"]')
await expect(nodeBody).toBeVisible()

await nodeBody.click({ button: 'right' })
await comfyPage.nextFrame()

// The PrimeVue node context menu should appear
const nodeMenu = comfyPage.page.locator('.p-contextmenu')
await expect(nodeMenu).toBeVisible()

// Slot-specific items should NOT be present
await expect(
comfyPage.page.getByRole('menuitem', { name: 'Disconnect Links' })
).toBeHidden()
})

test('Right-clicking an output slot dot shows the slot context menu', async ({
comfyPage
}) => {
const checkpointNode = comfyPage.vueNodes.getNodeByTitle('Load Checkpoint')
const outputSlot = checkpointNode.locator('.lg-slot--output').first()
await expect(outputSlot).toBeVisible()

await outputSlot.locator('.slot-dot').click({ button: 'right' })

const slotMenu = comfyPage.page.locator(
'div[role="menu"]:not(.p-contextmenu)'
)
await expect(slotMenu).toBeVisible()

await expect(
slotMenu.getByRole('menuitem', { name: 'Rename' })
).toBeVisible()
})

test('Slot context menu closes when clicking outside', async ({
comfyPage
}) => {
const ksamplerNode = comfyPage.vueNodes.getNodeByTitle('KSampler')
const inputSlot = ksamplerNode.locator('.lg-slot--input').first()
await expect(inputSlot).toBeVisible()

await inputSlot.locator('.slot-dot').click({ button: 'right' })

const slotMenu = comfyPage.page.locator(
'div[role="menu"]:not(.p-contextmenu)'
)
await expect(slotMenu).toBeVisible()

// Press Escape to close the menu
await comfyPage.page.keyboard.press('Escape')

await expect(slotMenu).toBeHidden()
})

test('Rename Slot updates the slot label reactively in the DOM', async ({
comfyPage
}) => {
// Find a KSampler input slot that is renamable (not widget-backed)
const slotInfo = await comfyPage.page.evaluate(() => {
const graph = window.app!.graph!
const node = graph.findNodesByType('KSampler', [])[0]
if (!node?.inputs) return null
const idx = node.inputs.findIndex(
(i) => !i.nameLocked && !('widget' in i && i.widget)
)
if (idx < 0) return null
return {
index: idx,
originalName: node.inputs[idx].label || node.inputs[idx].name
}
})
expect(slotInfo).not.toBeNull()

const ksamplerNode = comfyPage.vueNodes.getNodeByTitle('KSampler')
const inputSlot = ksamplerNode
.locator('.lg-slot--input')
.nth(slotInfo!.index)
await expect(inputSlot).toBeVisible()

// Right-click to open slot context menu
await inputSlot.locator('.slot-dot').click({ button: 'right' })

const slotMenu = comfyPage.page.locator(
'div[role="menu"]:not(.p-contextmenu)'
)
await expect(slotMenu).toBeVisible()

// Click "Rename"
await slotMenu.getByRole('menuitem', { name: 'Rename' }).click()

// Menu should close, prompt dialog should appear
await expect(slotMenu).toBeHidden()

const promptInput = comfyPage.page.locator('.prompt-dialog-content input')
await expect(promptInput).toBeVisible()

// Type a new name and confirm
await promptInput.fill('MyCustomSlot')
await comfyPage.page.locator('.prompt-dialog-content button').click()

// Wait for dialog to close
await expect(promptInput).toBeHidden()
await comfyPage.nextFrame()

// The slot label in the DOM should reactively reflect the new name
await expect(inputSlot).toContainText('MyCustomSlot')

// Verify the underlying graph data also changed
const labelInGraph = await comfyPage.page.evaluate((idx) => {
const graph = window.app!.graph!
const node = graph.findNodesByType('KSampler', [])[0]
return node?.inputs?.[idx]?.label
}, slotInfo!.index)
expect(labelInGraph).toBe('MyCustomSlot')
})

test('Slot context menu Disconnect Links removes connections', async ({
comfyPage
}) => {
// Use page.evaluate to find a KSampler input with an active link
const connectedSlot = await comfyPage.page.evaluate(() => {
const graph = window.app!.graph!
const nodes = graph.findNodesByType('KSampler', [])
const ksamplerNode = nodes.find((n) =>
n.inputs?.some((i) => i.link != null)
)
if (!ksamplerNode) return null
const slotIndex = ksamplerNode.inputs!.findIndex((i) => i.link != null)
return { nodeId: ksamplerNode.id, slotIndex }
})
expect(connectedSlot).not.toBeNull()

// Find the corresponding Vue input slot by node ID
const ksamplerNode = comfyPage.page.locator(
`[data-node-id="${connectedSlot!.nodeId}"]`
)
const inputSlot = ksamplerNode
.locator('.lg-slot--input')
.nth(connectedSlot!.slotIndex)
await expect(inputSlot).toBeVisible()

await inputSlot.locator('.slot-dot').click({ button: 'right' })

const slotMenu = comfyPage.page.locator(
'div[role="menu"]:not(.p-contextmenu)'
)
await expect(slotMenu).toBeVisible()

await expect(
slotMenu.getByRole('menuitem', { name: 'Disconnect Links' })
).toBeVisible()

await slotMenu.getByRole('menuitem', { name: 'Disconnect Links' }).click()

// Menu should close
await expect(slotMenu).toBeHidden()

// Verify the link was removed in the graph
const linkRemoved = await comfyPage.page.evaluate(
({ nodeId, slotIndex }) => {
const graph = window.app!.graph!
const node = graph.getNodeById(nodeId)
return node?.inputs?.[slotIndex]?.link == null
},
connectedSlot!
)
expect(linkRemoved).toBe(true)
})
})
2 changes: 2 additions & 0 deletions src/components/graph/GraphCanvas.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
<TitleEditor />
<SelectionToolbox v-if="selectionToolboxEnabled" />
<NodeContextMenu />
<SlotContextMenu v-if="shouldRenderVueNodes" />
<!-- Render legacy DOM widgets only when Vue nodes are disabled -->
<DomWidgets v-if="!shouldRenderVueNodes" />
</template>
Expand Down Expand Up @@ -154,6 +155,7 @@ import NodeContextMenu from '@/components/graph/NodeContextMenu.vue'
import NodeDragPreview from '@/components/graph/NodeDragPreview.vue'
import NodeSelectionModeBanner from '@/components/graph/NodeSelectionModeBanner.vue'
import SelectionToolbox from '@/components/graph/SelectionToolbox.vue'
import SlotContextMenu from '@/components/graph/SlotContextMenu.vue'
import TitleEditor from '@/components/graph/TitleEditor.vue'
import NodePropertiesPanel from '@/components/rightSidePanel/RightSidePanel.vue'
import { useAgentDockMount } from '@/workbench/extensions/agent/composables/useAgentDockMount'
Expand Down
81 changes: 7 additions & 74 deletions src/components/graph/NodeContextMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@
</template>

<script setup lang="ts">
import { useElementBounding, useEventListener, useRafFn } from '@vueuse/core'
import { useEventListener } from '@vueuse/core'
import ContextMenu from 'primevue/contextmenu'
import type { MenuItem } from 'primevue/menuitem'
import { computed, onMounted, onUnmounted, ref, watchEffect } from 'vue'

import { useCanvasAnchoredPosition } from '@/composables/graph/useCanvasAnchoredPosition'
import {
registerNodeOptionsInstance,
useMoreOptionsMenu
Expand All @@ -59,7 +60,6 @@ import type {
MenuOption,
SubMenuOption
} from '@/composables/graph/useMoreOptionsMenu'
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'

import SubmenuPopover from './selectionToolbox/SubmenuPopover.vue'

Expand All @@ -76,66 +76,17 @@ const shapeSubmenu = ref<InstanceType<typeof SubmenuPopover>>()
const isOpen = ref(false)

const { menuOptions, bump } = useMoreOptionsMenu()
const canvasStore = useCanvasStore()
const { screenPosition, anchorToEvent } = useCanvasAnchoredPosition(isOpen)

// World position (canvas coordinates) where menu was opened
const worldPosition = ref({ x: 0, y: 0 })

// Get canvas bounding rect reactively
const lgCanvas = canvasStore.getCanvas()
const { left: canvasLeft, top: canvasTop } = useElementBounding(lgCanvas.canvas)

// Track last canvas transform to detect actual changes
let lastScale = 0
let lastOffsetX = 0
let lastOffsetY = 0

// Update menu position based on canvas transform
const updateMenuPosition = () => {
watchEffect(() => {
if (!isOpen.value) return

const menuInstance = contextMenu.value as unknown as {
container?: HTMLElement
}
const menuEl = menuInstance?.container
if (!menuEl) return

const { scale, offset } = lgCanvas.ds

// Only update if canvas transform actually changed
if (
scale === lastScale &&
offset[0] === lastOffsetX &&
offset[1] === lastOffsetY
) {
return
}

lastScale = scale
lastOffsetX = offset[0]
lastOffsetY = offset[1]

// Convert world position to screen position
const screenX = (worldPosition.value.x + offset[0]) * scale + canvasLeft.value
const screenY = (worldPosition.value.y + offset[1]) * scale + canvasTop.value

// Update menu position
menuEl.style.left = `${screenX}px`
menuEl.style.top = `${screenY}px`
}

// Sync with canvas transform using requestAnimationFrame
const { resume: startSync, pause: stopSync } = useRafFn(updateMenuPosition, {
immediate: false
})

// Start/stop syncing based on menu visibility
watchEffect(() => {
if (isOpen.value) {
startSync()
} else {
stopSync()
}
menuEl.style.left = `${screenPosition.value.x}px`
menuEl.style.top = `${screenPosition.value.y}px`
})

// Close on touch outside to handle mobile devices where click might be swallowed
Expand Down Expand Up @@ -217,25 +168,7 @@ const menuItems = computed<ExtendedMenuItem[]>(() =>
// Show context menu
function show(event: MouseEvent) {
bump()

// Convert screen position to world coordinates
// Screen position relative to canvas = event position - canvas offset
const screenX = event.clientX - canvasLeft.value
const screenY = event.clientY - canvasTop.value

// Convert to world coordinates using canvas transform
const { scale, offset } = lgCanvas.ds
worldPosition.value = {
x: screenX / scale - offset[0],
y: screenY / scale - offset[1]
}

// Initialize last* values to current transform to prevent updateMenuPosition
// from overwriting PrimeVue's flip-adjusted position on the first RAF tick
lastScale = scale
lastOffsetX = offset[0]
lastOffsetY = offset[1]

anchorToEvent(event)
isOpen.value = true
contextMenu.value?.show(event)
}
Expand Down
Loading
Loading