Fix output name persistence: use comma-separated like reference impl
JSON.stringify format for hidden widget values didn't survive ComfyUI's serialization round-trip. Switch to comma-separated strings matching the proven ComfyUI-JSON-Dynamic implementation. Remove properties-based approach in favor of the simpler, working pattern. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -117,16 +117,11 @@ app.registerExtension({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store keys and types for persistence
|
// Store keys and types in hidden widgets for persistence (comma-separated)
|
||||||
// Properties are always reliably serialized by LiteGraph
|
|
||||||
this.properties = this.properties || {};
|
|
||||||
this.properties._output_keys = keys;
|
|
||||||
this.properties._output_types = types;
|
|
||||||
// Also update hidden widgets for Python-side access
|
|
||||||
const okWidget = this.widgets?.find(w => w.name === "output_keys");
|
const okWidget = this.widgets?.find(w => w.name === "output_keys");
|
||||||
if (okWidget) okWidget.value = JSON.stringify(keys);
|
if (okWidget) okWidget.value = keys.join(",");
|
||||||
const otWidget = this.widgets?.find(w => w.name === "output_types");
|
const otWidget = this.widgets?.find(w => w.name === "output_types");
|
||||||
if (otWidget) otWidget.value = JSON.stringify(types);
|
if (otWidget) otWidget.value = types.join(",");
|
||||||
|
|
||||||
// Slot 0 is always total_sequences (INT) — ensure it exists
|
// Slot 0 is always total_sequences (INT) — ensure it exists
|
||||||
if (this.outputs.length === 0 || this.outputs[0].name !== "total_sequences") {
|
if (this.outputs.length === 0 || this.outputs[0].name !== "total_sequences") {
|
||||||
@@ -202,23 +197,12 @@ app.registerExtension({
|
|||||||
const okWidget = this.widgets?.find(w => w.name === "output_keys");
|
const okWidget = this.widgets?.find(w => w.name === "output_keys");
|
||||||
const otWidget = this.widgets?.find(w => w.name === "output_types");
|
const otWidget = this.widgets?.find(w => w.name === "output_types");
|
||||||
|
|
||||||
// Read keys/types — properties (always persisted) first, then widgets
|
const keys = okWidget?.value
|
||||||
let keys = [];
|
? okWidget.value.split(",").filter(k => k.trim())
|
||||||
if (Array.isArray(this.properties?._output_keys) && this.properties._output_keys.length > 0) {
|
: [];
|
||||||
keys = this.properties._output_keys;
|
const types = otWidget?.value
|
||||||
} else if (okWidget?.value) {
|
? otWidget.value.split(",")
|
||||||
try { keys = JSON.parse(okWidget.value); } catch (_) {
|
: [];
|
||||||
keys = okWidget.value.split(",").map(k => k.trim()).filter(Boolean);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let types = [];
|
|
||||||
if (Array.isArray(this.properties?._output_types) && this.properties._output_types.length > 0) {
|
|
||||||
types = this.properties._output_types;
|
|
||||||
} else if (otWidget?.value) {
|
|
||||||
try { types = JSON.parse(otWidget.value); } catch (_) {
|
|
||||||
types = otWidget.value.split(",").map(t => t.trim()).filter(Boolean);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure slot 0 is total_sequences (INT)
|
// Ensure slot 0 is total_sequences (INT)
|
||||||
if (this.outputs.length === 0 || this.outputs[0].name !== "total_sequences") {
|
if (this.outputs.length === 0 || this.outputs[0].name !== "total_sequences") {
|
||||||
@@ -258,7 +242,7 @@ app.registerExtension({
|
|||||||
for (let i = 0; i < keys.length; i++) {
|
for (let i = 0; i < keys.length; i++) {
|
||||||
const slotIdx = i + 1; // offset by 1 for total_sequences
|
const slotIdx = i + 1; // offset by 1 for total_sequences
|
||||||
if (slotIdx < this.outputs.length) {
|
if (slotIdx < this.outputs.length) {
|
||||||
this.outputs[slotIdx].name = keys[i];
|
this.outputs[slotIdx].name = keys[i].trim();
|
||||||
if (types[i]) this.outputs[slotIdx].type = types[i];
|
if (types[i]) this.outputs[slotIdx].type = types[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -268,16 +252,11 @@ app.registerExtension({
|
|||||||
this.removeOutput(this.outputs.length - 1);
|
this.removeOutput(this.outputs.length - 1);
|
||||||
}
|
}
|
||||||
} else if (this.outputs.length > 1) {
|
} else if (this.outputs.length > 1) {
|
||||||
// Widget/property values empty but serialized dynamic outputs exist —
|
// Widget values empty but serialized dynamic outputs exist — sync widgets
|
||||||
// sync from the outputs LiteGraph already restored (fallback, skip slot 0).
|
// from the outputs LiteGraph already restored (fallback, skip slot 0).
|
||||||
const dynamicOutputs = this.outputs.slice(1);
|
const dynamicOutputs = this.outputs.slice(1);
|
||||||
const restoredKeys = dynamicOutputs.map(o => o.name);
|
if (okWidget) okWidget.value = dynamicOutputs.map(o => o.name).join(",");
|
||||||
const restoredTypes = dynamicOutputs.map(o => o.type);
|
if (otWidget) otWidget.value = dynamicOutputs.map(o => o.type).join(",");
|
||||||
this.properties = this.properties || {};
|
|
||||||
this.properties._output_keys = restoredKeys;
|
|
||||||
this.properties._output_types = restoredTypes;
|
|
||||||
if (okWidget) okWidget.value = JSON.stringify(restoredKeys);
|
|
||||||
if (otWidget) otWidget.value = JSON.stringify(restoredTypes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setSize(this.computeSize());
|
this.setSize(this.computeSize());
|
||||||
|
|||||||
Reference in New Issue
Block a user