From 40963b5a16f717a636c98dae0055224938852c6a Mon Sep 17 00:00:00 2001 From: comfyanonymous Date: Thu, 26 Oct 2023 19:52:41 -0400 Subject: [PATCH] Apply primitive nodes to graph before serializing workflow. --- web/scripts/app.js | 14 ++++++++++---- web/scripts/ui.js | 28 +++++++++++++++------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/web/scripts/app.js b/web/scripts/app.js index fca5b5bd31e..583310a27c7 100644 --- a/web/scripts/app.js +++ b/web/scripts/app.js @@ -1586,6 +1586,16 @@ export class ComfyApp { * @returns The workflow and node links */ async graphToPrompt() { + for (const node of this.graph.computeExecutionOrder(false)) { + if (node.isVirtualNode) { + // Don't serialize frontend only nodes but let them make changes + if (node.applyToGraph) { + node.applyToGraph(); + } + continue; + } + } + const workflow = this.graph.serialize(); const output = {}; // Process nodes in order of execution @@ -1593,10 +1603,6 @@ export class ComfyApp { const n = workflow.nodes.find((n) => n.id === node.id); if (node.isVirtualNode) { - // Don't serialize frontend only nodes but let them make changes - if (node.applyToGraph) { - node.applyToGraph(workflow); - } continue; } diff --git a/web/scripts/ui.js b/web/scripts/ui.js index c3b3fbda114..6f01aa5b245 100644 --- a/web/scripts/ui.js +++ b/web/scripts/ui.js @@ -719,20 +719,22 @@ export class ComfyUI { filename += ".json"; } } - const json = JSON.stringify(app.graph.serialize(), null, 2); // convert the data to a JSON string - const blob = new Blob([json], {type: "application/json"}); - const url = URL.createObjectURL(blob); - const a = $el("a", { - href: url, - download: filename, - style: {display: "none"}, - parent: document.body, + app.graphToPrompt().then(p=>{ + const json = JSON.stringify(p.workflow, null, 2); // convert the data to a JSON string + const blob = new Blob([json], {type: "application/json"}); + const url = URL.createObjectURL(blob); + const a = $el("a", { + href: url, + download: filename, + style: {display: "none"}, + parent: document.body, + }); + a.click(); + setTimeout(function () { + a.remove(); + window.URL.revokeObjectURL(url); + }, 0); }); - a.click(); - setTimeout(function () { - a.remove(); - window.URL.revokeObjectURL(url); - }, 0); }, }), $el("button", {