Fix serialize issue caused by comfy by a workaround of adding dummy items

This commit is contained in:
Will Miao
2025-03-02 17:09:01 +08:00
parent 3b5e6c8bba
commit 988d298008
5 changed files with 35 additions and 24 deletions

View File

@@ -53,8 +53,6 @@ class LoraManagerLoader:
"""Loads multiple LoRAs based on the kwargs input."""
loaded_loras = []
all_trigger_words = []
print(f"kwargs: {kwargs}")
if 'loras' in kwargs:
for lora in kwargs['loras']:

View File

@@ -29,8 +29,6 @@ class TriggerWordToggle:
"id": id,
"message": trigger_words
})
print(f"kwargs: {kwargs}")
filtered_triggers = trigger_words

View File

@@ -73,15 +73,7 @@ app.registerExtension({
node.lorasWidget.value = mergedLoras;
// node.graph.setDirtyCanvas(true, true);
};
console.log("node: ", node);
});
}
},
async nodeRemoved(node) {
if (node.comfyClass === "Lora Loader (LoraManager)") {
// TODO: Remove widget from node
}
},
});

View File

@@ -15,7 +15,7 @@ export function addLorasWidget(node, name, opts, callback) {
});
// Initialize default value
const defaultValue = opts?.defaultVal || "";
const defaultValue = opts?.defaultVal || [];
// Parse LoRA entries from value
const parseLoraValue = (value) => {
@@ -247,7 +247,11 @@ export function addLorasWidget(node, name, opts, callback) {
textAlign: "center",
padding: "20px 0",
color: "rgba(226, 232, 240, 0.8)",
fontStyle: "italic"
fontStyle: "italic",
userSelect: "none", // Add this line to prevent text selection
WebkitUserSelect: "none", // For Safari support
MozUserSelect: "none", // For Firefox support
msUserSelect: "none", // For IE/Edge support
});
container.appendChild(emptyMessage);
return;
@@ -283,6 +287,10 @@ export function addLorasWidget(node, name, opts, callback) {
color: "rgba(226, 232, 240, 0.8)",
fontSize: "13px",
marginLeft: "8px",
userSelect: "none", // Add this line to prevent text selection
WebkitUserSelect: "none", // For Safari support
MozUserSelect: "none", // For Firefox support
msUserSelect: "none", // For IE/Edge support
});
const toggleContainer = document.createElement("div");
@@ -299,7 +307,11 @@ export function addLorasWidget(node, name, opts, callback) {
Object.assign(strengthLabel.style, {
color: "rgba(226, 232, 240, 0.8)",
fontSize: "13px",
marginRight: "8px"
marginRight: "8px",
userSelect: "none", // Add this line to prevent text selection
WebkitUserSelect: "none", // For Safari support
MozUserSelect: "none", // For Firefox support
msUserSelect: "none", // For IE/Edge support
});
header.appendChild(toggleContainer);
@@ -350,6 +362,10 @@ export function addLorasWidget(node, name, opts, callback) {
color: active ? "rgba(226, 232, 240, 0.9)" : "rgba(226, 232, 240, 0.6)",
fontSize: "13px",
cursor: "pointer", // Add pointer cursor to indicate hoverable area
userSelect: "none", // Add this line to prevent text selection
WebkitUserSelect: "none", // For Safari support
MozUserSelect: "none", // For Firefox support
msUserSelect: "none", // For IE/Edge support
});
// Move preview tooltip events to nameEl instead of loraEl
@@ -530,18 +546,17 @@ export function addLorasWidget(node, name, opts, callback) {
},
});
// Initialize widget value using options methods
widget.options.setValue(defaultValue);
widget.value = defaultValue;
widget.callback = callback;
// widget.computeSize = (width) => {
// // console.log("loras_widget computeSize called: ", width, height);
// return [400, 200];
// };
// Render initial state
renderLoras(widgetValue, widget);
widget.serializeValue = () => {
// Add dummy items to avoid the 2-element serialization issue, a bug in comfyui
return [...widgetValue,
{ name: "__dummy_item1__", strength: 0, active: false, _isDummy: true },
{ name: "__dummy_item2__", strength: 0, active: false, _isDummy: true }
];
}
widget.onRemove = () => {
container.remove();

View File

@@ -126,5 +126,13 @@ export function addTagsWidget(node, name, opts, callback) {
widget.callback = callback;
widget.serializeValue = () => {
// Add dummy items to avoid the 2-element serialization issue, a bug in comfyui
return [...widgetValue,
{ text: "__dummy_item__", active: false, _isDummy: true },
{ text: "__dummy_item__", active: false, _isDummy: true }
];
};
return { minWidth: 300, minHeight: 150, widget };
}