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
This commit is contained in:
Alexander Brown
2026-10-24 05:56:26 +00:00
parent 7e1af9c202
commit 5fe4b0cea7
+8 -4
View File
@@ -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();