diff --git a/src/LGraphNode.ts b/src/LGraphNode.ts index 02f6c6083..1563551fe 100644 --- a/src/LGraphNode.ts +++ b/src/LGraphNode.ts @@ -856,8 +856,7 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { if (links) { for (const id of links) { const link = this.graph._links.get(id) - if (!link) continue - link.type = type + if (link) link.type = type } } } @@ -1417,9 +1416,7 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { if (!this.graph) throw new NullGraphError() const link = this.graph._links.get(linkId) - if (!link) continue - - link.origin_slot-- + if (link) link.origin_slot-- } } @@ -1483,9 +1480,7 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { if (!this.graph) throw new NullGraphError() const link = this.graph._links.get(input.link) - if (!link) continue - - link.target_slot-- + if (link) link.target_slot-- } this.onInputRemoved?.(slot, slot_info[0]) this.setDirtyCanvas(true, true) @@ -2641,43 +2636,41 @@ export class LGraphNode implements Positionable, IPinnable, IColorable { for (const [i, link_id] of links.entries()) { const link_info = graph._links.get(link_id) + if (link_info?.target_id != target.id) continue // is the link we are searching for... - if (link_info?.target_id == target.id) { - // remove here - links.splice(i, 1) - const input = target.inputs[link_info.target_slot] - // remove there - input.link = null + // remove here + links.splice(i, 1) + const input = target.inputs[link_info.target_slot] + // remove there + input.link = null - // remove the link from the links pool - link_info.disconnect(graph, "input") - graph._version++ + // remove the link from the links pool + link_info.disconnect(graph, "input") + graph._version++ - // link_info hasn't been modified so its ok - target.onConnectionsChange?.( - NodeSlotType.INPUT, - link_info.target_slot, - false, - link_info, - input, - ) - this.onConnectionsChange?.( - NodeSlotType.OUTPUT, - slot, - false, - link_info, - output, - ) + // link_info hasn't been modified so its ok + target.onConnectionsChange?.( + NodeSlotType.INPUT, + link_info.target_slot, + false, + link_info, + input, + ) + this.onConnectionsChange?.( + NodeSlotType.OUTPUT, + slot, + false, + link_info, + output, + ) - break - } + break } } else { // all the links in this output slot for (const link_id of links) { const link_info = graph._links.get(link_id) - // bug: it happens sometimes if (!link_info) continue const target = graph.getNodeById(link_info.target_id) diff --git a/src/Reroute.ts b/src/Reroute.ts index 910093a27..d5d08578c 100644 --- a/src/Reroute.ts +++ b/src/Reroute.ts @@ -199,10 +199,10 @@ export class Reroute implements Positionable, LinkSegment, Serialisable, floatingLinks: ReadonlyMap): boolean { const { linkIds, floatingLinkIds } = this for (const linkId of linkIds) { - if (!links.get(linkId)) linkIds.delete(linkId) + if (!links.has(linkId)) linkIds.delete(linkId) } for (const linkId of floatingLinkIds) { - if (!floatingLinks.get(linkId)) floatingLinkIds.delete(linkId) + if (!floatingLinks.has(linkId)) floatingLinkIds.delete(linkId) } return linkIds.size > 0 || floatingLinkIds.size > 0 } diff --git a/src/canvas/MovingRenderLink.ts b/src/canvas/MovingRenderLink.ts index 834f6564f..7fe0fdd5f 100644 --- a/src/canvas/MovingRenderLink.ts +++ b/src/canvas/MovingRenderLink.ts @@ -54,10 +54,10 @@ export class MovingRenderLink implements RenderLink { // Store output info const outputNode = network.getNodeById(outputNodeId) ?? undefined - if (!outputNode) throw new Error(`Creating DraggingRenderLink for link [${link.id}] failed: Output node [${outputNodeId}] not found.`) + if (!outputNode) throw new Error(`Creating MovingRenderLink for link [${link.id}] failed: Output node [${outputNodeId}] not found.`) const outputSlot = outputNode.outputs.at(outputIndex) - if (!outputSlot) throw new Error(`Creating DraggingRenderLink for link [${link.id}] failed: Output slot [${outputIndex}] not found.`) + if (!outputSlot) throw new Error(`Creating MovingRenderLink for link [${link.id}] failed: Output slot [${outputIndex}] not found.`) this.outputNodeId = outputNodeId this.outputNode = outputNode