fix(nodes): restore autocomplete widget sync after metadata insertion (#879)

This commit is contained in:
Will Miao
2026-03-29 10:09:39 +08:00
parent 2626dbab8e
commit 301ab14781
6 changed files with 110 additions and 17 deletions

View File

@@ -7,6 +7,8 @@ import {
mergeLoras,
getAllGraphNodes,
getNodeFromGraph,
getWidgetByName,
getWidgetSerializedValue,
} from "./utils.js";
import { addLorasWidget } from "./loras_widget.js";
import { applyLoraValuesToText, debounce } from "./lora_syntax_utils.js";
@@ -148,7 +150,11 @@ app.registerExtension({
};
// Get the text input widget (AUTOCOMPLETE_TEXT_LORAS type, created by Vue widgets)
const inputWidget = this.widgets[0];
const inputWidget = getWidgetByName(this, "text");
if (!inputWidget) {
console.warn("LoRA Manager: text widget not found for Lora Loader");
return;
}
this.inputWidget = inputWidget;
const scheduleInputSync = debounce((lorasValue) => {
@@ -227,12 +233,16 @@ app.registerExtension({
// Restore saved value if exists
let existingLoras = [];
if (node.widgets_values && node.widgets_values.length > 0) {
// 0 for input widget, 1 for loras widget
const savedValue = node.widgets_values[1];
const savedValue = getWidgetSerializedValue(node, "loras");
existingLoras = savedValue || [];
}
// Merge the loras data
const mergedLoras = mergeLoras(node.widgets[0].value, existingLoras);
const inputWidget = node.inputWidget || getWidgetByName(node, "text");
if (!inputWidget) {
console.warn("LoRA Manager: text widget not found while restoring Lora Loader");
return;
}
const mergedLoras = mergeLoras(inputWidget.value, existingLoras);
node.lorasWidget.value = mergedLoras;
}
},

View File

@@ -5,6 +5,8 @@ import {
updateDownstreamLoaders,
chainCallback,
mergeLoras,
getWidgetByName,
getWidgetSerializedValue,
} from "./utils.js";
import { addLorasWidget } from "./loras_widget.js";
import { applyLoraValuesToText, debounce } from "./lora_syntax_utils.js";
@@ -28,7 +30,11 @@ app.registerExtension({
let isSyncingInput = false;
// Get the text input widget (AUTOCOMPLETE_TEXT_LORAS type, created by Vue widgets)
const inputWidget = this.widgets[0];
const inputWidget = getWidgetByName(this, "text");
if (!inputWidget) {
console.warn("LoRA Manager: text widget not found for Lora Stacker");
return;
}
this.inputWidget = inputWidget;
const scheduleInputSync = debounce((lorasValue) => {
@@ -122,12 +128,15 @@ app.registerExtension({
// Restore saved value if exists
let existingLoras = [];
if (node.widgets_values && node.widgets_values.length > 0) {
// 0 for input widget, 1 for loras widget
const savedValue = node.widgets_values[1];
const savedValue = getWidgetSerializedValue(node, "loras");
existingLoras = savedValue || [];
}
// Merge the loras data
const inputWidget = node.inputWidget || node.widgets[0];
const inputWidget = node.inputWidget || getWidgetByName(node, "text");
if (!inputWidget) {
console.warn("LoRA Manager: text widget not found while restoring Lora Stacker");
return;
}
const mergedLoras = mergeLoras(inputWidget.value, existingLoras);
node.lorasWidget.value = mergedLoras;
}

View File

@@ -114,6 +114,27 @@ export function getNodeKey(node) {
return `${getNodeGraphId(node)}:${node.id}`;
}
export function getWidgetByName(node, widgetName) {
if (!node || !Array.isArray(node.widgets)) {
return null;
}
return node.widgets.find((widget) => widget?.name === widgetName) || null;
}
export function getWidgetSerializedValue(node, widgetName) {
if (!node || !Array.isArray(node.widgets) || !Array.isArray(node.widgets_values)) {
return undefined;
}
const widgetIndex = node.widgets.findIndex((widget) => widget?.name === widgetName);
if (widgetIndex === -1) {
return undefined;
}
return node.widgets_values[widgetIndex];
}
export function getLinkFromGraph(graph, linkId) {
if (!graph || graph.links == null) {
return null;

View File

@@ -4,6 +4,8 @@ import {
updateConnectedTriggerWords,
chainCallback,
mergeLoras,
getWidgetByName,
getWidgetSerializedValue,
} from "./utils.js";
import { addLorasWidget } from "./loras_widget.js";
import { applyLoraValuesToText, debounce } from "./lora_syntax_utils.js";
@@ -31,7 +33,11 @@ app.registerExtension({
let isSyncingInput = false;
// Get the text input widget (AUTOCOMPLETE_TEXT_LORAS type, at index 2 after low_mem_load and merge_loras)
const inputWidget = this.widgets[2];
const inputWidget = getWidgetByName(this, "text");
if (!inputWidget) {
console.warn("LoRA Manager: text widget not found for WanVideo Lora Select");
return;
}
this.inputWidget = inputWidget;
const scheduleInputSync = debounce((lorasValue) => {
@@ -107,12 +113,15 @@ app.registerExtension({
// Restore saved value if exists
let existingLoras = [];
if (node.widgets_values && node.widgets_values.length > 0) {
// 0 for low_mem_load, 1 for merge_loras, 2 for text widget, 3 for loras widget
const savedValue = node.widgets_values[3];
const savedValue = getWidgetSerializedValue(node, "loras");
existingLoras = savedValue || [];
}
// Merge the loras data
const inputWidget = node.inputWidget || node.widgets[2];
const inputWidget = node.inputWidget || getWidgetByName(node, "text");
if (!inputWidget) {
console.warn("LoRA Manager: text widget not found while restoring WanVideo Lora Select");
return;
}
const mergedLoras = mergeLoras(inputWidget.value, existingLoras);
node.lorasWidget.value = mergedLoras;
}