From 2f6b4a72c591994ec95b4adccad25a10ac43fa2c Mon Sep 17 00:00:00 2001 From: unclehooru <276176178+unclehooru@users.noreply.github.com> Date: Tue, 27 Oct 2026 22:03:22 +0900 Subject: [PATCH] Fix copy/clone disconnecting links on the original node On ComfyUI frontend 1.53.1+ (after the ECS migration), slot links are resolved from the graph's link store by (graph, node id, slot) instead of `input.link`. A cloned node keeps the original's id, and RgthreeBaseNode.clone() attached the original graph to the clone as a workaround for ComfyUI_frontend#5037. As a result: - BaseAnyInputConnectedNode.clone() trimming extra inputs with removeInput() disconnected input slots 1+ of the ORIGINAL node (Fast Bypasser/Muter, Mute/Bypass Repeater/Relay, Random Unmuter, Node Collector, Fast Actions Button) on single-node copy, clone, duplicate, alt+drag clone and "Save Selected as Template". - DynamicContextNodeBase.clone() also cut the original's outputs 1+. - The graph-attached clone serialized the original's link ids. Trim the clone's slot arrays directly (they carry no links) and stop attaching the graph to clones, so clones behave like stock clones. Co-Authored-By: Claude Code --- src_web/comfyui/base_any_input_connected_node.ts | 8 +++++--- src_web/comfyui/base_node.ts | 12 ++++++------ src_web/comfyui/dynamic_context_base.ts | 11 +++++------ web/comfyui/base_any_input_connected_node.js | 4 +--- web/comfyui/base_node.js | 1 - web/comfyui/dynamic_context_base.js | 8 ++------ 6 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src_web/comfyui/base_any_input_connected_node.ts b/src_web/comfyui/base_any_input_connected_node.ts index d54279a9..f67edc13 100644 --- a/src_web/comfyui/base_any_input_connected_node.ts +++ b/src_web/comfyui/base_any_input_connected_node.ts @@ -57,9 +57,11 @@ export class BaseAnyInputConnectedNode extends RgthreeBaseVirtualNode { // so if it's pasted/templatized the data is correct. Otherwise, clear the inputs and so the new // node is ready to go, fresh. if (!rgthree.canvasCurrentlyCopyingToClipboardWithMultipleNodes) { - while (cloned.inputs.length > 1) { - cloned.removeInput(cloned.inputs.length - 1); - } + // Trim the slot array directly rather than calling `removeInput()`. The clone shares the + // original's id, and newer frontends resolve slot links from the graph's link store by node + // id, so `removeInput()` on a graph-attached clone disconnects the ORIGINAL node's links + // (and on a graph-less clone, older frontends threw). The clone's inputs carry no links. + cloned.inputs.splice(1); if (cloned.inputs[0]) { cloned.inputs[0].label = ""; } diff --git a/src_web/comfyui/base_node.ts b/src_web/comfyui/base_node.ts index 3ce74ab1..3ea9f4f9 100644 --- a/src_web/comfyui/base_node.ts +++ b/src_web/comfyui/base_node.ts @@ -179,12 +179,12 @@ export abstract class RgthreeBaseNode extends LGraphNode { if (cloned?.properties && !!window.structuredClone) { cloned.properties = structuredClone(cloned.properties); } - // [🤮] https://github.com/Comfy-Org/ComfyUI_frontend/issues/5037 - // ComfyUI started throwing errors when some of our nodes wanted to remove inputs when cloning - // (like our dynamic inputs) because the disconnect method that's automatically called assumes - // there should be a graph. For now, I _think_ we can simply assign the current graph to avoid - // the error, which would then be overwritten when placed... - cloned.graph = this.graph; + // NOTE: We used to assign `cloned.graph = this.graph` here to work around + // https://github.com/Comfy-Org/ComfyUI_frontend/issues/5037 (removing inputs on a graph-less + // clone threw). That is no longer needed since subclasses now trim their clone's slot arrays + // directly, and it became harmful: the clone keeps the original's id, and newer frontends + // resolve slot links from the graph's link store by node id, so a graph-attached clone both + // serializes the original's links and disconnects them when its slots are removed. return cloned; } diff --git a/src_web/comfyui/dynamic_context_base.ts b/src_web/comfyui/dynamic_context_base.ts index 17cbb72d..b0fabc27 100644 --- a/src_web/comfyui/dynamic_context_base.ts +++ b/src_web/comfyui/dynamic_context_base.ts @@ -97,15 +97,14 @@ export class DynamicContextNodeBase extends BaseContextNode { } override clone() { const cloned = super.clone()! as DynamicContextNodeBase; - while (cloned.inputs.length > 1) { - cloned.removeInput(cloned.inputs.length - 1); - } + // Trim slot arrays directly rather than calling `removeInput()`/`removeOutput()`. The clone + // shares the original's id, and newer frontends resolve slot links from the graph's link store + // by node id, so those calls on a graph-attached clone disconnect the ORIGINAL node's links. + cloned.inputs.splice(1); while (cloned.widgets.length > 1) { cloned.removeWidget(cloned.widgets.length - 1); } - while (cloned.outputs.length > 1) { - cloned.removeOutput(cloned.outputs.length - 1); - } + cloned.outputs.splice(1); return cloned; } diff --git a/web/comfyui/base_any_input_connected_node.js b/web/comfyui/base_any_input_connected_node.js index 09e2950c..2c04bc1a 100644 --- a/web/comfyui/base_any_input_connected_node.js +++ b/web/comfyui/base_any_input_connected_node.js @@ -17,9 +17,7 @@ export class BaseAnyInputConnectedNode extends RgthreeBaseVirtualNode { clone() { const cloned = super.clone(); if (!rgthree.canvasCurrentlyCopyingToClipboardWithMultipleNodes) { - while (cloned.inputs.length > 1) { - cloned.removeInput(cloned.inputs.length - 1); - } + cloned.inputs.splice(1); if (cloned.inputs[0]) { cloned.inputs[0].label = ""; } diff --git a/web/comfyui/base_node.js b/web/comfyui/base_node.js index 11fbe52f..317bd95d 100644 --- a/web/comfyui/base_node.js +++ b/web/comfyui/base_node.js @@ -91,7 +91,6 @@ export class RgthreeBaseNode extends LGraphNode { if ((cloned === null || cloned === void 0 ? void 0 : cloned.properties) && !!window.structuredClone) { cloned.properties = structuredClone(cloned.properties); } - cloned.graph = this.graph; return cloned; } onModeChange(from, to) { diff --git a/web/comfyui/dynamic_context_base.js b/web/comfyui/dynamic_context_base.js index 4ead4a61..62af1b5b 100644 --- a/web/comfyui/dynamic_context_base.js +++ b/web/comfyui/dynamic_context_base.js @@ -65,15 +65,11 @@ export class DynamicContextNodeBase extends BaseContextNode { } clone() { const cloned = super.clone(); - while (cloned.inputs.length > 1) { - cloned.removeInput(cloned.inputs.length - 1); - } + cloned.inputs.splice(1); while (cloned.widgets.length > 1) { cloned.removeWidget(cloned.widgets.length - 1); } - while (cloned.outputs.length > 1) { - cloned.removeOutput(cloned.outputs.length - 1); - } + cloned.outputs.splice(1); return cloned; } onNodeCreated() {