From 985dab7e1cfdf9e4039e51257f01c50658281953 Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Fri, 16 May 2025 00:48:56 +1000 Subject: [PATCH] Allow LGraph.configure to be made recursive (#3894) --- src/scripts/app.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/scripts/app.ts b/src/scripts/app.ts index 96062adab7..86ea2f8e05 100644 --- a/src/scripts/app.ts +++ b/src/scripts/app.ts @@ -143,13 +143,20 @@ export class ComfyApp { _nodeOutputs: Record nodePreviewImages: Record // @ts-expect-error fixme ts strict error - graph: LGraph + #graph: LGraph + get graph() { + return this.#graph + } // @ts-expect-error fixme ts strict error canvas: LGraphCanvas dragOverNode: LGraphNode | null = null // @ts-expect-error fixme ts strict error canvasEl: HTMLCanvasElement - configuringGraph: boolean = false + + #configuringGraphLevel: number = 0 + get configuringGraph() { + return this.#configuringGraphLevel > 0 + } // @ts-expect-error fixme ts strict error ctx: CanvasRenderingContext2D bodyTop: HTMLElement @@ -692,17 +699,16 @@ export class ComfyApp { api.init() } + /** Flag that the graph is configuring to prevent nodes from running checks while its still loading */ #addConfigureHandler() { const app = this const configure = LGraph.prototype.configure - // Flag that the graph is configuring to prevent nodes from running checks while its still loading - LGraph.prototype.configure = function () { - app.configuringGraph = true + LGraph.prototype.configure = function (...args) { + app.#configuringGraphLevel++ try { - // @ts-expect-error fixme ts strict error - return configure.apply(this, arguments) + return configure.apply(this, args) } finally { - app.configuringGraph = false + app.#configuringGraphLevel-- } } } @@ -756,7 +762,7 @@ export class ComfyApp { this.#addConfigureHandler() this.#addApiUpdateHandlers() - this.graph = new LGraph() + this.#graph = new LGraph() this.#addAfterConfigureHandler()