Skip to content

Commit 591c4e1

Browse files
authored
Remove Infinite Loop in asyncDialog
Modified the 'close' event listener to only resolve the Promise without calling this.close() to eliminate the infinite loop causing violation messages. There might be better ways to do this, I'm sure there are, but as long as we kill the infinite loop I don't care how it's done. 😁
1 parent 9bdb3c0 commit 591c4e1

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/scripts/ui/components/asyncDialog.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ export class ComfyAsyncDialog extends ComfyDialog<HTMLDialogElement> {
2121
}
2222

2323
show(html: string | HTMLElement | HTMLElement[]) {
24-
this.element.addEventListener('close', () => {
25-
this.close()
26-
})
24+
const onClose = () => {
25+
this.#resolve(null)
26+
}
27+
28+
this.element.addEventListener('close', onClose, { once: true }) // Resovle promise without calling onClose() to prevent infinite loop, added once:true for safety but probably not needed
2729

2830
super.show(html)
2931

@@ -33,9 +35,11 @@ export class ComfyAsyncDialog extends ComfyDialog<HTMLDialogElement> {
3335
}
3436

3537
showModal(html: string | HTMLElement | HTMLElement[]) {
36-
this.element.addEventListener('close', () => {
37-
this.close()
38-
})
38+
const onClose = () => {
39+
this.#resolve(null)
40+
}
41+
42+
this.element.addEventListener('close', onClose, { once: true }) // same as show
3943

4044
super.show(html)
4145
this.element.showModal()

0 commit comments

Comments
 (0)