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() {