Fix "Dragging from input slot connected to SubgraphInputNode creates new link instead of moving existing one" (#1184)

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: bymyself <cbyrne@comfy.org>
This commit is contained in:
Benjamin Lu
2025-08-02 00:56:41 -04:00
committed by GitHub
parent 46a486c694
commit a568c0651f
5 changed files with 127 additions and 23 deletions

View File

@@ -1,6 +1,9 @@
import { describe, expect, it } from "vitest"
import { describe, expect, it, vi } from "vitest"
import { LGraphNode } from "@/litegraph"
import { LinkConnector } from "@/canvas/LinkConnector"
import { ToInputFromIoNodeLink } from "@/canvas/ToInputFromIoNodeLink"
import { SUBGRAPH_INPUT_ID } from "@/constants"
import { LGraphNode, type LinkNetwork } from "@/litegraph"
import { NodeInputSlot } from "@/node/NodeInputSlot"
import { NodeOutputSlot } from "@/node/NodeOutputSlot"
import { isSubgraphInput, isSubgraphOutput } from "@/subgraph/subgraphUtils"
@@ -103,6 +106,55 @@ describe("Subgraph slot connections", () => {
})
})
describe("LinkConnector dragging behavior", () => {
it("should drag existing link when dragging from input slot connected to subgraph input node", () => {
// Create a subgraph with one input
const subgraph = createTestSubgraph({
inputs: [{ name: "input1", type: "number" }],
})
// Create a node inside the subgraph
const internalNode = new LGraphNode("InternalNode")
internalNode.id = 100
internalNode.addInput("in", "number")
subgraph.add(internalNode)
// Connect the subgraph input to the internal node's input
const link = subgraph.inputNode.slots[0].connect(internalNode.inputs[0], internalNode)
expect(link).toBeDefined()
expect(link!.origin_id).toBe(SUBGRAPH_INPUT_ID)
expect(link!.target_id).toBe(internalNode.id)
// Verify the input slot has the link
expect(internalNode.inputs[0].link).toBe(link!.id)
// Create a LinkConnector
const setConnectingLinks = vi.fn()
const connector = new LinkConnector(setConnectingLinks)
// Now try to drag from the input slot
connector.moveInputLink(subgraph as LinkNetwork, internalNode.inputs[0])
// Verify that we're dragging the existing link
expect(connector.isConnecting).toBe(true)
expect(connector.state.connectingTo).toBe("input")
expect(connector.state.draggingExistingLinks).toBe(true)
// Check that we have exactly one render link
expect(connector.renderLinks).toHaveLength(1)
// The render link should be a ToInputFromIoNodeLink, not MovingInputLink
expect(connector.renderLinks[0]).toBeInstanceOf(ToInputFromIoNodeLink)
// The input links collection should contain our link
expect(connector.inputLinks).toHaveLength(1)
expect(connector.inputLinks[0]).toBe(link)
// Verify the link is marked as dragging
expect(link!._dragging).toBe(true)
})
})
describe("Type compatibility", () => {
it("should respect type compatibility for SubgraphInput connections", () => {
const subgraph = createTestSubgraph({

View File

@@ -1,7 +1,7 @@
import type { ISlotType } from "@/interfaces"
import type { TWidgetType } from "@/types/widgets"
import { describe, expect, it, vi } from "vitest"
import { describe, expect, it } from "vitest"
import { LGraphNode, Subgraph } from "@/litegraph"
import { BaseWidget } from "@/widgets/BaseWidget"
@@ -339,7 +339,7 @@ describe("SubgraphWidgetPromotion", () => {
// The promoted widget should preserve the original tooltip
expect(promotedWidget.tooltip).toBe(originalTooltip)
// The promoted widget should still function normally
expect(promotedWidget.name).toBe("value") // Uses subgraph input name
expect(promotedWidget.type).toBe("number")