From 31b784bac495160436a8cd91bf1a856cf01a738e Mon Sep 17 00:00:00 2001 From: rgthree Date: Mon, 17 Feb 2025 18:37:26 -0500 Subject: [PATCH] Ensures weird LiteGraph submenu calling also calls extensions' overrides. Fixes #369 and #417 --- src_web/comfyui/menu_auto_nest.ts | 15 ++++++++++++--- web/comfyui/menu_auto_nest.js | 7 +++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src_web/comfyui/menu_auto_nest.ts b/src_web/comfyui/menu_auto_nest.ts index c1267ab..1d650a7 100644 --- a/src_web/comfyui/menu_auto_nest.ts +++ b/src_web/comfyui/menu_auto_nest.ts @@ -135,9 +135,18 @@ app.registerExtension({ if (options.scale == null) { options.scale = Math.max(app.canvas.ds?.scale || 1, 1); } - return existingContextMenu.call(this as any, values, options); - }; - LiteGraph.ContextMenu.prototype = existingContextMenu.prototype; + const oldCtrResponse = existingContextMenu.call(this as any, values, options); + // For some reason, LiteGraph calls submenus with "this.constructor" which no longer allows + // us to continue building deep nesting, as well as skips many other extensions (even + // ComfyUI's core extensions like translations) from working on submenus. It also removes + // search, etc. While this is a recent-ish issue, I can't seem to find the culpit as it looks + // like old litegraph always did this. Perhaps changing it to a Class? Anyway, this fixes it; + // Hopefully without issues. + if ((oldCtrResponse as any)?.constructor) { + (oldCtrResponse as any).constructor = LiteGraph.ContextMenu; + } + return this; + }; }, }); diff --git a/web/comfyui/menu_auto_nest.js b/web/comfyui/menu_auto_nest.js index da251ce..0fa78eb 100644 --- a/web/comfyui/menu_auto_nest.js +++ b/web/comfyui/menu_auto_nest.js @@ -103,8 +103,11 @@ app.registerExtension({ if (options.scale == null) { options.scale = Math.max(((_f = app.canvas.ds) === null || _f === void 0 ? void 0 : _f.scale) || 1, 1); } - return existingContextMenu.call(this, values, options); + const oldCtrResponse = existingContextMenu.call(this, values, options); + if (oldCtrResponse === null || oldCtrResponse === void 0 ? void 0 : oldCtrResponse.constructor) { + oldCtrResponse.constructor = LiteGraph.ContextMenu; + } + return this; }; - LiteGraph.ContextMenu.prototype = existingContextMenu.prototype; }, });