From 22afa45bf9be1f06e79242f91acbea8c3f30f89b Mon Sep 17 00:00:00 2001 From: rgthree Date: Mon, 18 Aug 2025 08:54:38 -0400 Subject: [PATCH] Turns ou, graph.subgraphs is an optional property; maybe older comfyuis. Fixes #561 --- pyproject.toml | 2 +- .../comfyui/services/fast_groups_service.ts | 8 ++++--- src_web/comfyui/utils.ts | 20 +++++++++------- web/comfyui/services/fast_groups_service.js | 12 ++++++---- web/comfyui/utils.js | 24 +++++++++++-------- 5 files changed, 39 insertions(+), 27 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b591f8d..25ec0d6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "rgthree-comfy" description = "Making ComfyUI more comfortable." -version = "1.0.2508162219" +version = "1.0.2508180854" license = { file = "LICENSE" } dependencies = [] diff --git a/src_web/comfyui/services/fast_groups_service.ts b/src_web/comfyui/services/fast_groups_service.ts index 6d6866b..007b835 100644 --- a/src_web/comfyui/services/fast_groups_service.ts +++ b/src_web/comfyui/services/fast_groups_service.ts @@ -166,9 +166,11 @@ class FastGroupsService { (!this.groupsUnsorted.length || now - this.msLastUnsorted > this.msThreshold) ) { this.groupsUnsorted = [...graph._groups]; - const subgraphs = graph.subgraphs.values(); - let s; - while ((s = subgraphs.next().value)) this.groupsUnsorted.push(...(s.groups ?? [])); + const subgraphs = graph.subgraphs?.values(); + if (subgraphs) { + let s; + while ((s = subgraphs.next().value)) this.groupsUnsorted.push(...(s.groups ?? [])); + } for (const group of this.groupsUnsorted) { this.recomputeInsideNodesForGroup(group); group.rgthree_hasAnyActiveNode = getGroupNodes(group).some( diff --git a/src_web/comfyui/utils.ts b/src_web/comfyui/utils.ts index 51ecde7..15c2532 100644 --- a/src_web/comfyui/utils.ts +++ b/src_web/comfyui/utils.ts @@ -787,10 +787,12 @@ export function getLinkById(linkId?: number | null) { if (linkId == null) return null; let link: LLink | null = app.graph.links[linkId] ?? null; link = link ?? app.canvas.getCurrentGraph()?.links[linkId] ?? null; - const subgraphs = app.graph.rootGraph.subgraphs.values(); - let subgraph; - while (!link && (subgraph = subgraphs.next().value)) { - link = subgraph?.links[linkId] ?? null; + const subgraphs = app.graph.rootGraph.subgraphs?.values(); + if (subgraphs) { + let subgraph; + while (!link && (subgraph = subgraphs.next().value)) { + link = subgraph?.links[linkId] ?? null; + } } return link; } @@ -802,10 +804,12 @@ export function getNodeById(id: NodeId) { if (id == null) return null; let node = app.graph.getNodeById(id); node = node ?? app.canvas.getCurrentGraph()?.getNodeById(id) ?? null; - const subgraphs = app.graph.rootGraph.subgraphs.values(); - let subgraph; - while (!node && (subgraph = subgraphs.next().value)) { - node = subgraph?.getNodeById(id) ?? null; + const subgraphs = app.graph.rootGraph.subgraphs?.values(); + if (subgraphs) { + let subgraph; + while (!node && (subgraph = subgraphs.next().value)) { + node = subgraph?.getNodeById(id) ?? null; + } } return node; } diff --git a/web/comfyui/services/fast_groups_service.js b/web/comfyui/services/fast_groups_service.js index 84d288d..72d0be6 100644 --- a/web/comfyui/services/fast_groups_service.js +++ b/web/comfyui/services/fast_groups_service.js @@ -102,16 +102,18 @@ class FastGroupsService { } } getGroupsUnsorted(now) { - var _a, _b; + var _a, _b, _c; const canvas = app.canvas; const graph = (_a = canvas.getCurrentGraph()) !== null && _a !== void 0 ? _a : app.graph; if (!canvas.selected_group_moving && (!this.groupsUnsorted.length || now - this.msLastUnsorted > this.msThreshold)) { this.groupsUnsorted = [...graph._groups]; - const subgraphs = graph.subgraphs.values(); - let s; - while ((s = subgraphs.next().value)) - this.groupsUnsorted.push(...((_b = s.groups) !== null && _b !== void 0 ? _b : [])); + const subgraphs = (_b = graph.subgraphs) === null || _b === void 0 ? void 0 : _b.values(); + if (subgraphs) { + let s; + while ((s = subgraphs.next().value)) + this.groupsUnsorted.push(...((_c = s.groups) !== null && _c !== void 0 ? _c : [])); + } for (const group of this.groupsUnsorted) { this.recomputeInsideNodesForGroup(group); group.rgthree_hasAnyActiveNode = getGroupNodes(group).some((n) => n.mode === LiteGraph.ALWAYS); diff --git a/web/comfyui/utils.js b/web/comfyui/utils.js index 2254984..5e6ac2f 100644 --- a/web/comfyui/utils.js +++ b/web/comfyui/utils.js @@ -513,28 +513,32 @@ export function getOriginNodeByLink(linkId) { return node; } export function getLinkById(linkId) { - var _a, _b, _c, _d; + var _a, _b, _c, _d, _e; if (linkId == null) return null; let link = (_a = app.graph.links[linkId]) !== null && _a !== void 0 ? _a : null; link = (_c = link !== null && link !== void 0 ? link : (_b = app.canvas.getCurrentGraph()) === null || _b === void 0 ? void 0 : _b.links[linkId]) !== null && _c !== void 0 ? _c : null; - const subgraphs = app.graph.rootGraph.subgraphs.values(); - let subgraph; - while (!link && (subgraph = subgraphs.next().value)) { - link = (_d = subgraph === null || subgraph === void 0 ? void 0 : subgraph.links[linkId]) !== null && _d !== void 0 ? _d : null; + const subgraphs = (_d = app.graph.rootGraph.subgraphs) === null || _d === void 0 ? void 0 : _d.values(); + if (subgraphs) { + let subgraph; + while (!link && (subgraph = subgraphs.next().value)) { + link = (_e = subgraph === null || subgraph === void 0 ? void 0 : subgraph.links[linkId]) !== null && _e !== void 0 ? _e : null; + } } return link; } export function getNodeById(id) { - var _a, _b, _c; + var _a, _b, _c, _d; if (id == null) return null; let node = app.graph.getNodeById(id); node = (_b = node !== null && node !== void 0 ? node : (_a = app.canvas.getCurrentGraph()) === null || _a === void 0 ? void 0 : _a.getNodeById(id)) !== null && _b !== void 0 ? _b : null; - const subgraphs = app.graph.rootGraph.subgraphs.values(); - let subgraph; - while (!node && (subgraph = subgraphs.next().value)) { - node = (_c = subgraph === null || subgraph === void 0 ? void 0 : subgraph.getNodeById(id)) !== null && _c !== void 0 ? _c : null; + const subgraphs = (_c = app.graph.rootGraph.subgraphs) === null || _c === void 0 ? void 0 : _c.values(); + if (subgraphs) { + let subgraph; + while (!node && (subgraph = subgraphs.next().value)) { + node = (_d = subgraph === null || subgraph === void 0 ? void 0 : subgraph.getNodeById(id)) !== null && _d !== void 0 ? _d : null; + } } return node; }