From e9ddf2950700ce5aa2c0410291c9e742ce6264ef Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Fri, 15 Aug 2025 14:35:11 -0700 Subject: [PATCH] [bugfix] Preserve nested subgraph widget values during serialization (#5023) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../litegraph/src/subgraph/SubgraphNode.ts | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/lib/litegraph/src/subgraph/SubgraphNode.ts b/src/lib/litegraph/src/subgraph/SubgraphNode.ts index 57c86894c..8ee6dcdc6 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphNode.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphNode.ts @@ -16,7 +16,10 @@ import type { GraphOrSubgraph, Subgraph } from '@/lib/litegraph/src/subgraph/Subgraph' -import type { ExportedSubgraphInstance } from '@/lib/litegraph/src/types/serialisation' +import type { + ExportedSubgraphInstance, + ISerialisedNode +} from '@/lib/litegraph/src/types/serialisation' import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' import type { UUID } from '@/lib/litegraph/src/utils/uuid' import { toConcreteWidget } from '@/lib/litegraph/src/widgets/widgetMap' @@ -540,4 +543,36 @@ export class SubgraphNode extends LGraphNode implements BaseLGraph { } } } + + /** + * Synchronizes widget values from this SubgraphNode instance to the + * corresponding widgets in the subgraph definition before serialization. + * This ensures nested subgraph widget values are preserved when saving. + */ + override serialize(): ISerialisedNode { + // Sync widget values to subgraph definition before serialization + for (let i = 0; i < this.widgets.length; i++) { + const widget = this.widgets[i] + const input = this.inputs.find((inp) => inp.name === widget.name) + + if (input) { + const subgraphInput = this.subgraph.inputNode.slots.find( + (slot) => slot.name === input.name + ) + + if (subgraphInput) { + // Find all widgets connected to this subgraph input + const connectedWidgets = subgraphInput.getConnectedWidgets() + + // Update the value of all connected widgets + for (const connectedWidget of connectedWidgets) { + connectedWidget.value = widget.value + } + } + } + } + + // Call parent serialize method + return super.serialize() + } }