From 6a823e21a0833ea2941fb3186982636d727948c5 Mon Sep 17 00:00:00 2001 From: bezo97 Date: Sun, 27 Oct 2024 14:20:48 +0100 Subject: [PATCH] Bugfix node widgets wrongly being prepared for qeueing on saving the workflow - calling graphToPrompt() invokes beforeQueued() which should not happen when saving the workflow --- src/scripts/app.ts | 20 ++++++++++++++------ src/scripts/workflows.ts | 4 ++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/scripts/app.ts b/src/scripts/app.ts index d9167b64..8a14fa98 100644 --- a/src/scripts/app.ts +++ b/src/scripts/app.ts @@ -1910,8 +1910,7 @@ export class ComfyApp { // Save current workflow automatically setInterval(() => { - const sortNodes = useSettingStore().get('Comfy.Workflow.SortNodeIdOnSave') - const workflow = JSON.stringify(this.graph.serialize({ sortNodes })) + const workflow = JSON.stringify(this.serializeGraph()) localStorage.setItem('workflow', workflow) if (api.clientId) { sessionStorage.setItem(`workflow:${api.clientId}`, workflow) @@ -2445,7 +2444,18 @@ export class ComfyApp { } /** - * Converts the current graph workflow for sending to the API + * Serializes a graph using preferred user settings. + * @param graph The litegraph to serialize. + * @returns A serialized graph (aka workflow) with preferred user settings. + */ + serializeGraph(graph: LGraph = this.graph) { + const sortNodes = useSettingStore().get('Comfy.Workflow.SortNodeIdOnSave') + return graph.serialize({ sortNodes }) + } + + /** + * Converts the current graph workflow for sending to the API. + * Note: Node widgets are updated before serialization to prepare queueing. * @returns The workflow and node links */ async graphToPrompt(graph = this.graph, clean = true) { @@ -2471,9 +2481,7 @@ export class ComfyApp { } } - const sortNodes = useSettingStore().get('Comfy.Workflow.SortNodeIdOnSave') - - const workflow = graph.serialize({ sortNodes }) + const workflow = this.serializeGraph(graph) const output = {} // Process nodes in order of execution for (const outerNode of graph.computeExecutionOrder(false)) { diff --git a/src/scripts/workflows.ts b/src/scripts/workflows.ts index 5e8846fd..2179ae2a 100644 --- a/src/scripts/workflows.ts +++ b/src/scripts/workflows.ts @@ -380,8 +380,8 @@ export class ComfyWorkflow { path = appendJsonExt(path) - const p = await this.manager.app.graphToPrompt() - const json = JSON.stringify(p.workflow, null, 2) + const workflow = this.manager.app.serializeGraph() + const json = JSON.stringify(workflow, null, 2) let resp = await api.storeUserData('workflows/' + path, json, { stringify: false, throwOnError: false,