Skip to content
Open
Show file tree
Hide file tree
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
13 changes: 6 additions & 7 deletions src/lib/litegraph/src/LGraphNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -851,13 +851,12 @@ export class LGraphNode
}

if (info.widgets_values) {
const widgetsWithValue = this.widgets
.values()
.filter((w) => w.serialize !== false)
.filter((_w, idx) => idx < info.widgets_values!.length)
widgetsWithValue.forEach(
(widget, i) => (widget.value = info.widgets_values![i])
)
let i = 0
for (const widget of this.widgets ?? []) {
if (widget.serialize === false) continue
if (i >= info.widgets_values.length) break
widget.value = info.widgets_values[i++]
}
Comment on lines 853 to +859
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Widget deserialisation index mismatch with serialize() (can mis-load existing workflows)

This loop fixes the .values().filter iterator issue, but it no longer matches how serialize() writes widgets_values:

  • serialize() uses for (const [i, widget] of widgets.entries()) and stores values at the original widget index i, skipping serialize === false widgets with continue.
  • After JSON round‑trip, widgets_values is effectively an array indexed by widget position (with null in “holes” created by non‑serialisable widgets).

The new configure logic, however, compacts by serialisable widgets:

  • It increments i only for widget.serialize !== false and reads info.widgets_values[i].
  • If there are non‑serialisable widgets interleaved, later serialisable widgets will read from the wrong index (e.g. second serialisable widget reads widgets_values[1] instead of widgets_values[2]), corrupting widget state for existing saved workflows.

This is a functional/backwards‑compatibility issue, even though the original runtime error is fixed.

To keep old‑browser compatibility and align with the existing serialize() format, you can use an index‑based loop over this.widgets and index widgets_values by widget position:

-      if (info.widgets_values) {
-        let i = 0
-        for (const widget of this.widgets ?? []) {
-          if (widget.serialize === false) continue
-          if (i >= info.widgets_values.length) break
-          widget.value = info.widgets_values[i++]
-        }
-      }
+      const { widgets_values } = info
+      if (widgets_values && this.widgets?.length) {
+        const widgets = this.widgets
+        const max = Math.min(widgets.length, widgets_values.length)
+
+        for (let index = 0; index < max; index++) {
+          const widget = widgets[index]
+          if (!widget || widget.serialize === false) continue
+
+          const value = widgets_values[index]
+          if (value !== undefined) widget.value = value
+        }
+      }

This:

  • Avoids .values()/iterator methods (fixing the original error on older browsers).
  • Keeps widgets_values aligned with the current serialize() contract.
  • Avoids clobbering defaults when no value was saved (by skipping undefined).
🤖 Prompt for AI Agents
In src/lib/litegraph/src/LGraphNode.ts around lines 853 to 859, the configure
loop compacts serialisable widgets and reads info.widgets_values sequentially,
which mismatches serialize() that stores values at the original widget index and
causes mis-loaded workflows; replace the iterator-based loop with an index-based
loop over this.widgets that accesses info.widgets_values by the same widget
index (avoid using .values()/iterators for old-browser compatibility), skip
undefined entries so defaults aren’t clobbered, and preserve the serialize ===
false behavior by not overwriting a widget when its corresponding widgets_values
entry is undefined.

}
}

Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"lib": [
"ES2023",
"ES2023.Array",
"ESNext.Iterator",
"DOM",
"DOM.Iterable"
],
Expand Down