Skip to content
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
cleanup: Utility function to filter for relevant outputs when shift+c…
…licking
  • Loading branch information
DrJKL committed Aug 20, 2025
commit c038a5b287c27f741abf49593acb613f0d429288
38 changes: 19 additions & 19 deletions src/lib/litegraph/src/LGraphCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import type {
INodeSlot,
INodeSlotContextItem,
ISlotType,
LinkNetwork,
LinkSegment,
NullableProperties,
Point,
Expand Down Expand Up @@ -2575,31 +2576,30 @@ export class LGraphCanvas
} else if (!node.flags.collapsed) {
const { inputs, outputs } = node

function hasRelevantOutputLinks(
output: INodeOutputSlot,
network: LinkNetwork
): boolean {
const outputLinks = [
...(output.links ?? []),
...[...(output._floatingLinks ?? new Set())]
]
return outputLinks.some(
(linkId) =>
typeof linkId === 'number' && network.getLink(linkId) !== undefined
)
Comment on lines +2583 to +2590
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change appears to discard errors caused by link corruption. Is this intentional? Not sure the state this is resolving, but it seems like there's a root cause elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the code that it mostly copies is for a single new connection, where we'd want to error, but in here, we have some state management issues that lead to stale references.
By continuing instead of noping out, we can move the remaining valid links.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The root cause is that we lack a single source of truth for links. The output slots have references, but so does the graph itself.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens to the stale references, though? If we just ignore them, the stale ID stays on the output slot right? Unless we adopt a "ignore stale links everywhere" approach (including a requirement for any extensions), it is likely we'll end up just pushing the issue somewhere else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we definitely need to address the links' state issue more fundamentally. But for now, this just stems the bleeding.

}

// Outputs
if (outputs) {
for (const [i, output] of outputs.entries()) {
const link_pos = node.getOutputPos(i)
if (isInRectangle(x, y, link_pos[0] - 15, link_pos[1] - 10, 30, 20)) {
// Drag multiple output links
if (
e.shiftKey &&
(output.links?.length || output._floatingLinks?.size)
) {
const outputLinks = [
...(output.links ?? []),
...[...(output._floatingLinks ?? new Set())]
]
if (
outputLinks.some(
(linkId) =>
typeof linkId === 'number' &&
graph.getLink(linkId) !== undefined
)
) {
linkConnector.moveOutputLink(graph, output)
this.#linkConnectorDrop()
return
}
if (e.shiftKey && hasRelevantOutputLinks(output, graph)) {
linkConnector.moveOutputLink(graph, output)
this.#linkConnectorDrop()
return
}

// New output link
Expand Down