Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix widget value corruption when input order changes (#4983)
- Replace index-based widget value mapping with name-based mapping
- Maintain backward compatibility with legacy array format
- Serialize widget values as {name, value} objects instead of plain arrays
- Prevent widget value corruption when JSON key ordering changes
- All existing tests pass (1213/1214)
  • Loading branch information
vivekchavan14 committed Aug 14, 2025
commit 3d60ebe1cfd2ce3edd5973dd4e58c6a5467ff0cd
46 changes: 39 additions & 7 deletions src/lib/litegraph/src/LGraphNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,10 +849,38 @@ export class LGraphNode
const widgetsWithValue = this.widgets.filter(
(w) => w.serialize !== false
)
for (let i = 0; i < info.widgets_values.length; ++i) {
const widget = widgetsWithValue[i]
if (widget) {
widget.value = info.widgets_values[i]

// Enhanced widget values restoration with name-based mapping
// Check if widgets_values contains name-based mapping (new format)
if (
Array.isArray(info.widgets_values) &&
info.widgets_values.length > 0 &&
info.widgets_values[0] &&
typeof info.widgets_values[0] === 'object' &&
'name' in info.widgets_values[0] &&
'value' in info.widgets_values[0]
) {
// New format: name-based mapping
const valuesByName = new Map()
for (const item of info.widgets_values as Array<{
name: string
value: any
}>) {
valuesByName.set(item.name, item.value)
}

for (const widget of widgetsWithValue) {
if (valuesByName.has(widget.name)) {
widget.value = valuesByName.get(widget.name)
}
}
} else {
// Legacy format: index-based mapping for backward compatibility
for (let i = 0; i < info.widgets_values.length; ++i) {
const widget = widgetsWithValue[i]
if (widget) {
widget.value = info.widgets_values[i]
}
}
}
}
Expand Down Expand Up @@ -896,11 +924,15 @@ export class LGraphNode

const { widgets } = this
if (widgets && this.serialize_widgets) {
// Use name-based mapping for widget values to ensure stable ordering
o.widgets_values = []
for (const [i, widget] of widgets.entries()) {
for (const widget of widgets) {
if (widget.serialize === false) continue
// @ts-expect-error #595 No-null
o.widgets_values[i] = widget ? widget.value : null
// Store widget value with name for stable mapping
o.widgets_values.push({
name: widget.name,
value: widget ? widget.value : null
})
}
}

Expand Down
Loading