Skip to content

Commit e9ddf29

Browse files
[bugfix] Preserve nested subgraph widget values during serialization (#5023)
When saving workflows with nested subgraphs, promoted widget values were not being synchronized back to the subgraph definitions before serialization. This caused widget values to revert to their original defaults when reloading the workflow. The fix overrides the serialize() method in SubgraphNode to sync promoted widget values to their corresponding widgets in the subgraph definition before serialization occurs. Fixes the issue where nested subgraph widget values would be lost after save/reload. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <[email protected]>
1 parent fdd8564 commit e9ddf29

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

src/lib/litegraph/src/subgraph/SubgraphNode.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ import type {
1616
GraphOrSubgraph,
1717
Subgraph
1818
} from '@/lib/litegraph/src/subgraph/Subgraph'
19-
import type { ExportedSubgraphInstance } from '@/lib/litegraph/src/types/serialisation'
19+
import type {
20+
ExportedSubgraphInstance,
21+
ISerialisedNode
22+
} from '@/lib/litegraph/src/types/serialisation'
2023
import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets'
2124
import type { UUID } from '@/lib/litegraph/src/utils/uuid'
2225
import { toConcreteWidget } from '@/lib/litegraph/src/widgets/widgetMap'
@@ -540,4 +543,36 @@ export class SubgraphNode extends LGraphNode implements BaseLGraph {
540543
}
541544
}
542545
}
546+
547+
/**
548+
* Synchronizes widget values from this SubgraphNode instance to the
549+
* corresponding widgets in the subgraph definition before serialization.
550+
* This ensures nested subgraph widget values are preserved when saving.
551+
*/
552+
override serialize(): ISerialisedNode {
553+
// Sync widget values to subgraph definition before serialization
554+
for (let i = 0; i < this.widgets.length; i++) {
555+
const widget = this.widgets[i]
556+
const input = this.inputs.find((inp) => inp.name === widget.name)
557+
558+
if (input) {
559+
const subgraphInput = this.subgraph.inputNode.slots.find(
560+
(slot) => slot.name === input.name
561+
)
562+
563+
if (subgraphInput) {
564+
// Find all widgets connected to this subgraph input
565+
const connectedWidgets = subgraphInput.getConnectedWidgets()
566+
567+
// Update the value of all connected widgets
568+
for (const connectedWidget of connectedWidgets) {
569+
connectedWidget.value = widget.value
570+
}
571+
}
572+
}
573+
}
574+
575+
// Call parent serialize method
576+
return super.serialize()
577+
}
543578
}

0 commit comments

Comments
 (0)