From 5fe4b0cea7f3ab062455d694ff7bc23fe9f34355 Mon Sep 17 00:00:00 2001 From: Alexander Brown Date: Sat, 24 Oct 2026 05:56:26 +0000 Subject: [PATCH] Reload components on clear of any root graph ComfyUI_frontend is moving to one LGraph instance per workflow tab (Comfy-Org/ComfyUI_frontend#21571), and app.clean() clears the new graph before any extension hook fires. The instance patch on app.graph.clear only reaches the graph that existed at startup, so components would not be reloaded for later workflows. Patch clear on the graph prototype and reload components when the cleared graph is the current root graph. This also stops a subgraph clear from clearing the root graph, which the old wrapper did by always calling orig_clear on app.graph. Amp-Thread-ID: https://ampcode.com/threads/T-d545a10a-f002-4dc5-9a74-f6402a836919 --- js/comfyui-manager.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/js/comfyui-manager.js b/js/comfyui-manager.js index 138708b65..efca23dec 100644 --- a/js/comfyui-manager.js +++ b/js/comfyui-manager.js @@ -1536,10 +1536,14 @@ app.registerExtension({ }); }, async setup() { - let orig_clear = app.graph.clear; - app.graph.clear = function () { - orig_clear.call(app.graph); - load_components(); + // Patch the prototype rather than the app.graph instance: newer frontends + // create a separate graph per workflow tab, so an instance patch would only + // ever see the graph that existed at startup. + const graphProto = Object.getPrototypeOf(app.graph); + const orig_clear = graphProto.clear; + graphProto.clear = function () { + orig_clear.apply(this, arguments); + if (this === app.graph) load_components(); }; load_components();