diff --git a/browser_tests/assets/subgraphs/subgraph-compressed-target-slot.json b/browser_tests/assets/subgraphs/subgraph-compressed-target-slot.json new file mode 100644 index 0000000000..471011d380 --- /dev/null +++ b/browser_tests/assets/subgraphs/subgraph-compressed-target-slot.json @@ -0,0 +1,150 @@ +{ + "id": "e0cb1d7e-5437-4911-b574-c9603dfbeaee", + "revision": 0, + "last_node_id": 2, + "last_link_id": 0, + "nodes": [ + { + "id": 2, + "type": "8bfe4227-f272-49e1-a892-0a972a86867c", + "pos": [ + -317, + -336 + ], + "size": [ + 210, + 58 + ], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [], + "outputs": [], + "properties": { + "proxyWidgets": [ + [ + "-1", + "batch_size" + ] + ] + }, + "widgets_values": [ + 1 + ] + } + ], + "links": [], + "groups": [], + "definitions": { + "subgraphs": [ + { + "id": "8bfe4227-f272-49e1-a892-0a972a86867c", + "version": 1, + "state": { + "lastGroupId": 0, + "lastNodeId": 1, + "lastLinkId": 1, + "lastRerouteId": 0 + }, + "revision": 0, + "config": {}, + "name": "New Subgraph", + "inputNode": { + "id": -10, + "bounding": [ + -562, + -358, + 120, + 60 + ] + }, + "outputNode": { + "id": -20, + "bounding": [ + -52, + -358, + 120, + 40 + ] + }, + "inputs": [ + { + "id": "b4a8bc2a-8e9f-41aa-938d-c567a11d2c00", + "name": "batch_size", + "type": "INT", + "linkIds": [ + 1 + ], + "pos": [ + -462, + -338 + ] + } + ], + "outputs": [], + "widgets": [], + "nodes": [ + { + "id": 1, + "type": "EmptyLatentImage", + "pos": [ + -382, + -376 + ], + "size": [ + 270, + 106 + ], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [ + { + "localized_name": "batch_size", + "name": "batch_size", + "type": "INT", + "widget": { + "name": "batch_size" + }, + "link": 1 + } + ], + "outputs": [ + { + "localized_name": "LATENT", + "name": "LATENT", + "type": "LATENT", + "links": null + } + ], + "properties": { + "Node name for S&R": "EmptyLatentImage" + }, + "widgets_values": [ + 512, + 512, + 1 + ] + } + ], + "groups": [], + "links": [ + { + "id": 1, + "origin_id": -10, + "origin_slot": 0, + "target_id": 1, + "target_slot": 0, + "type": "INT" + } + ], + "extra": {} + } + ] + }, + "config": {}, + "extra": { + "frontendVersion": "1.35.1" + }, + "version": 0.4 +} \ No newline at end of file diff --git a/browser_tests/tests/subgraph.spec.ts b/browser_tests/tests/subgraph.spec.ts index 06a09210c5..6359156211 100644 --- a/browser_tests/tests/subgraph.spec.ts +++ b/browser_tests/tests/subgraph.spec.ts @@ -329,6 +329,15 @@ test.describe('Subgraph Operations', () => { expect(newInputName).toBe(labelClickRenamedName) expect(newInputName).not.toBe(initialInputLabel) }) + test('Can create widget from link with compressed target_slot', async ({ + comfyPage + }) => { + await comfyPage.loadWorkflow('subgraphs/subgraph-compressed-target-slot') + const step = await comfyPage.page.evaluate(() => { + return window['app'].graph.nodes[0].widgets[0].options.step + }) + expect(step).toBe(10) + }) }) test.describe('Subgraph Creation and Deletion', () => { diff --git a/src/lib/litegraph/src/subgraph/SubgraphNode.ts b/src/lib/litegraph/src/subgraph/SubgraphNode.ts index 92b61460f6..43f59b5166 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphNode.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphNode.ts @@ -300,17 +300,24 @@ export class SubgraphNode extends LGraphNode implements BaseLGraph { continue } - const resolved = link.resolve(this.subgraph) - if (!resolved.input || !resolved.inputNode) { - console.warn('Invalid resolved link', resolved, this) + const { inputNode } = link.resolve(this.subgraph) + if (!inputNode) { + console.warn('Failed to resolve inputNode', link, this) + continue + } + + //Manually find input since target_slot can't be trusted + const targetInput = inputNode.inputs.find((inp) => inp.link === linkId) + if (!targetInput) { + console.warn('Failed to find corresponding input', link, inputNode) continue } // No widget - ignore this link - const widget = resolved.inputNode.getWidgetFromSlot(resolved.input) + const widget = inputNode.getWidgetFromSlot(targetInput) if (!widget) continue - this.#setWidget(subgraphInput, input, widget, resolved.input.widget) + this.#setWidget(subgraphInput, input, widget, targetInput.widget) break } }