From c4dabb8f98ae793aae544e5ca799b622e3010b92 Mon Sep 17 00:00:00 2001 From: Johnpaul Chiwetelu <49923152+Myestery@users.noreply.github.com> Date: Fri, 6 Mar 2026 23:24:49 +0100 Subject: [PATCH] refactor: extract input widget resolution from SubgraphNode configure (#9383) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Extract the inner link-resolution loop from `_internalConfigureAfterSlots` into a private `_resolveInputWidget` method to reduce cognitive complexity below the sonarjs threshold of 15. ## Changes - **What**: Extract nested loop body (lines 654-689) into `_resolveInputWidget` private method in `SubgraphNode.ts` - Pure refactoring with no behavioral changes ## Review Focus Straightforward extract-method refactoring. The new method contains the exact same logic that was previously inline. Fixes #9297 ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-9383-refactor-extract-input-widget-resolution-from-SubgraphNode-configure-3196d73d365081ba9124cfd0d312fcb0) by [Unito](https://www.unito.io) --- .../litegraph/src/subgraph/SubgraphNode.ts | 79 ++++++++++--------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/src/lib/litegraph/src/subgraph/SubgraphNode.ts b/src/lib/litegraph/src/subgraph/SubgraphNode.ts index 5f2066b024..735a0f27c7 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphNode.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphNode.ts @@ -649,49 +649,52 @@ export class SubgraphNode extends LGraphNode implements BaseLGraph { } this._addSubgraphInputListeners(subgraphInput, input) - - // Find the first widget that this slot is connected to - for (const linkId of subgraphInput.linkIds) { - const link = this.subgraph.getLink(linkId) - if (!link) { - console.warn( - `[SubgraphNode.configure] No link found for link ID ${linkId}`, - this - ) - continue - } - - 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 = inputNode.getWidgetFromSlot(targetInput) - if (!widget) continue - - this._setWidget( - subgraphInput, - input, - widget, - targetInput.widget, - inputNode - ) - break - } + this._resolveInputWidget(subgraphInput, input) } this._syncPromotions() } + private _resolveInputWidget( + subgraphInput: SubgraphInput, + input: INodeInputSlot + ) { + for (const linkId of subgraphInput.linkIds) { + const link = this.subgraph.getLink(linkId) + if (!link) { + console.warn( + `[SubgraphNode.configure] No link found for link ID ${linkId}`, + this + ) + continue + } + + const { inputNode } = link.resolve(this.subgraph) + if (!inputNode) { + console.warn('Failed to resolve inputNode', link, this) + continue + } + + const targetInput = inputNode.inputs.find((inp) => inp.link === linkId) + if (!targetInput) { + console.warn('Failed to find corresponding input', link, inputNode) + continue + } + + const widget = inputNode.getWidgetFromSlot(targetInput) + if (!widget) continue + + this._setWidget( + subgraphInput, + input, + widget, + targetInput.widget, + inputNode + ) + break + } + } + private _setWidget( subgraphInput: Readonly, input: INodeInputSlot,