From 393084877c71dc7dc9549b0f3694b02060151917 Mon Sep 17 00:00:00 2001 From: Farid Safi Date: Tue, 28 Mar 2023 19:45:17 +0200 Subject: [PATCH 1/2] clean state when loading another workflow --- web/scripts/app.js | 7 +++++++ web/scripts/ui.js | 11 +++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/web/scripts/app.js b/web/scripts/app.js index 609cc4cf..ddb829ab 100644 --- a/web/scripts/app.js +++ b/web/scripts/app.js @@ -903,6 +903,13 @@ class ComfyApp { } } } + + /** + * Clean current state + */ + clean() { + this.nodeOutputs = {}; + } } export const app = new ComfyApp(); diff --git a/web/scripts/ui.js b/web/scripts/ui.js index c79caaa9..7e73c108 100644 --- a/web/scripts/ui.js +++ b/web/scripts/ui.js @@ -306,6 +306,7 @@ export class ComfyUI { style: { display: "none" }, parent: document.body, onchange: () => { + app.clean(); app.handleFile(fileInput.files[0]); }, }); @@ -388,8 +389,14 @@ export class ComfyUI { }), $el("button", { textContent: "Load", onclick: () => fileInput.click() }), $el("button", { textContent: "Refresh", onclick: () => app.refreshComboInNodes() }), - $el("button", { textContent: "Clear", onclick: () => app.graph.clear() }), - $el("button", { textContent: "Load Default", onclick: () => app.loadGraphData() }), + $el("button", { textContent: "Clear", onclick: () => { + app.clean(); + app.graph.clear(); + }}), + $el("button", { textContent: "Load Default", onclick: () => { + app.clean(); + app.loadGraphData(); + }}), ]); dragElement(this.menuContainer); From 40a377775e7e383c09418297637a0cc261ead96d Mon Sep 17 00:00:00 2001 From: Farid Safi Date: Tue, 28 Mar 2023 20:22:49 +0200 Subject: [PATCH 2/2] move clean to handleFile and loadGraphData functions --- web/scripts/app.js | 2 ++ web/scripts/ui.js | 6 +----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/web/scripts/app.js b/web/scripts/app.js index ddb829ab..cd7fb5d1 100644 --- a/web/scripts/app.js +++ b/web/scripts/app.js @@ -721,6 +721,8 @@ class ComfyApp { * @param {*} graphData A serialized graph object */ loadGraphData(graphData) { + this.clean(); + if (!graphData) { graphData = defaultGraph; } diff --git a/web/scripts/ui.js b/web/scripts/ui.js index 7e73c108..2aabd29e 100644 --- a/web/scripts/ui.js +++ b/web/scripts/ui.js @@ -306,7 +306,6 @@ export class ComfyUI { style: { display: "none" }, parent: document.body, onchange: () => { - app.clean(); app.handleFile(fileInput.files[0]); }, }); @@ -393,10 +392,7 @@ export class ComfyUI { app.clean(); app.graph.clear(); }}), - $el("button", { textContent: "Load Default", onclick: () => { - app.clean(); - app.loadGraphData(); - }}), + $el("button", { textContent: "Load Default", onclick: () => app.loadGraphData() }), ]); dragElement(this.menuContainer);