From ce5a1ae3d0bdacca12f8bbef42d3353ac150409f Mon Sep 17 00:00:00 2001 From: Will Miao Date: Fri, 7 Nov 2025 14:21:58 +0800 Subject: [PATCH] feat(lora-stacker): conditionally update trigger words based on node mode Add node mode checks to ensure trigger words are only updated when the stacker node is active (mode 0 for Always or mode 3 for On Trigger). This prevents unnecessary updates when the node is inactive (mode 2 for Never or mode 4 for Bypass), improving performance and ensuring trigger words reflect the actual active state of the node. The changes include: - Adding mode checks before updating active LoRA names in the stacker callback - Modifying collectActiveLorasFromChain to only include active nodes - Adding comments to clarify node mode behavior --- web/comfyui/lora_stacker.js | 19 +++++++++++++------ web/comfyui/utils.js | 9 +++++++-- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/web/comfyui/lora_stacker.js b/web/comfyui/lora_stacker.js index bd6b0f77..59466b8a 100644 --- a/web/comfyui/lora_stacker.js +++ b/web/comfyui/lora_stacker.js @@ -63,12 +63,16 @@ app.registerExtension({ try { // Update this stacker's direct trigger toggles with its own active loras + // Only if the stacker node itself is active (mode 0 for Always, mode 3 for On Trigger) + const isNodeActive = this.mode === undefined || this.mode === 0 || this.mode === 3; const activeLoraNames = new Set(); - value.forEach((lora) => { - if (lora.active) { - activeLoraNames.add(lora.name); - } - }); + if (isNodeActive) { + value.forEach((lora) => { + if (lora.active) { + activeLoraNames.add(lora.name); + } + }); + } updateConnectedTriggerWords(this, activeLoraNames); // Find all Lora Loader nodes in the chain that might need updates @@ -94,7 +98,9 @@ app.registerExtension({ this.lorasWidget.value = mergedLoras; // Update this stacker's direct trigger toggles with its own active loras - const activeLoraNames = getActiveLorasFromNode(this); + // Only if the stacker node itself is active (mode 0 for Always, mode 3 for On Trigger) + const isNodeActive = this.mode === undefined || this.mode === 0 || this.mode === 3; + const activeLoraNames = isNodeActive ? getActiveLorasFromNode(this) : new Set(); updateConnectedTriggerWords(this, activeLoraNames); // Find all Lora Loader nodes in the chain that might need updates @@ -103,6 +109,7 @@ app.registerExtension({ isUpdating = false; } }; + inputWidget.callback = setupInputWidgetWithAutocomplete( this, inputWidget, diff --git a/web/comfyui/utils.js b/web/comfyui/utils.js index 7606eee8..60dc3b43 100644 --- a/web/comfyui/utils.js +++ b/web/comfyui/utils.js @@ -287,6 +287,7 @@ export function getActiveLorasFromNode(node) { } // Recursively collect all active loras from a node and its input chain +// A node is considered active only if its mode is 0 (Always) or 3 (On Trigger) export function collectActiveLorasFromChain(node, visited = new Set()) { // Prevent infinite loops from circular references const nodeKey = getNodeKey(node); @@ -298,8 +299,12 @@ export function collectActiveLorasFromChain(node, visited = new Set()) { } visited.add(nodeKey); - // Get active loras from current node - const allActiveLoraNames = getActiveLorasFromNode(node); + // Check if node is active (mode 0 for Always, mode 3 for On Trigger) + // Mode 2 is Never, Mode 4 is Bypass + const isNodeActive = node.mode === undefined || node.mode === 0 || node.mode === 3; + + // Get active loras from current node only if node is active + const allActiveLoraNames = isNodeActive ? getActiveLorasFromNode(node) : new Set(); // Get connected input stackers and collect their active loras const inputStackers = getConnectedInputStackers(node);