Skip to content

Commit 985dab7

Browse files
authored
Allow LGraph.configure to be made recursive (#3894)
1 parent 7f2b8a5 commit 985dab7

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/scripts/app.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,20 @@ export class ComfyApp {
143143
_nodeOutputs: Record<string, any>
144144
nodePreviewImages: Record<string, string[]>
145145
// @ts-expect-error fixme ts strict error
146-
graph: LGraph
146+
#graph: LGraph
147+
get graph() {
148+
return this.#graph
149+
}
147150
// @ts-expect-error fixme ts strict error
148151
canvas: LGraphCanvas
149152
dragOverNode: LGraphNode | null = null
150153
// @ts-expect-error fixme ts strict error
151154
canvasEl: HTMLCanvasElement
152-
configuringGraph: boolean = false
155+
156+
#configuringGraphLevel: number = 0
157+
get configuringGraph() {
158+
return this.#configuringGraphLevel > 0
159+
}
153160
// @ts-expect-error fixme ts strict error
154161
ctx: CanvasRenderingContext2D
155162
bodyTop: HTMLElement
@@ -692,17 +699,16 @@ export class ComfyApp {
692699
api.init()
693700
}
694701

702+
/** Flag that the graph is configuring to prevent nodes from running checks while its still loading */
695703
#addConfigureHandler() {
696704
const app = this
697705
const configure = LGraph.prototype.configure
698-
// Flag that the graph is configuring to prevent nodes from running checks while its still loading
699-
LGraph.prototype.configure = function () {
700-
app.configuringGraph = true
706+
LGraph.prototype.configure = function (...args) {
707+
app.#configuringGraphLevel++
701708
try {
702-
// @ts-expect-error fixme ts strict error
703-
return configure.apply(this, arguments)
709+
return configure.apply(this, args)
704710
} finally {
705-
app.configuringGraph = false
711+
app.#configuringGraphLevel--
706712
}
707713
}
708714
}
@@ -756,7 +762,7 @@ export class ComfyApp {
756762
this.#addConfigureHandler()
757763
this.#addApiUpdateHandlers()
758764

759-
this.graph = new LGraph()
765+
this.#graph = new LGraph()
760766

761767
this.#addAfterConfigureHandler()
762768

0 commit comments

Comments
 (0)