From 7e03436f59ed60ba263583507378f95115afa021 Mon Sep 17 00:00:00 2001 From: Amp Date: Tue, 22 Sep 2026 18:44:51 +0000 Subject: [PATCH] fix: preserve fast group toggle restrictions after widget adoption Amp-Thread-ID: https://ampcode.com/threads/T-01a0c564-c177-701a-b053-86d219fe1663 Co-authored-by: Alexander Brown --- src_web/comfyui/fast_groups_muter.ts | 4 +- .../tests/fast_groups_restriction_tests.ts | 73 +++++++++++++++++++ web/comfyui/fast_groups_muter.js | 4 +- 3 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 src_web/comfyui/tests/fast_groups_restriction_tests.ts diff --git a/src_web/comfyui/fast_groups_muter.ts b/src_web/comfyui/fast_groups_muter.ts index 4eee7f8c..99565f57 100644 --- a/src_web/comfyui/fast_groups_muter.ts +++ b/src_web/comfyui/fast_groups_muter.ts @@ -401,12 +401,12 @@ class FastGroupsToggleRowWidget extends RgthreeBaseWidget<{toggled: boolean}> { // TODO: This work should probably live in BaseFastGroupsModeChanger instead of the widgets. if (newValue && this.node.properties?.[PROPERTY_RESTRICTION]?.includes(" one")) { for (const widget of this.node.widgets) { - if (widget instanceof FastGroupsToggleRowWidget) { + if ("doModeChange" in widget && typeof widget.doModeChange === "function") { widget.doModeChange(false, true); } } } else if (!newValue && this.node.properties?.[PROPERTY_RESTRICTION] === "always one") { - newValue = this.node.widgets.every((w) => !w.value || w === this); + newValue = this.node.widgets.every((w) => w === this || !("toggled" in w && w.toggled)); } } changeModeOfNodes(getGroupNodes(this.group), (newValue ? this.node.modeOn : this.node.modeOff)); diff --git a/src_web/comfyui/tests/fast_groups_restriction_tests.ts b/src_web/comfyui/tests/fast_groups_restriction_tests.ts new file mode 100644 index 00000000..b8123be2 --- /dev/null +++ b/src_web/comfyui/tests/fast_groups_restriction_tests.ts @@ -0,0 +1,73 @@ +import {app} from "scripts/app.js"; +import {NodeTypesString} from "../constants.js"; +import {describe, expect, should} from "../testing/runner.js"; + +describe("TestFastGroupsRestrictions", async () => { + for (const {nodeType, modeOff} of [ + {nodeType: NodeTypesString.FAST_GROUPS_MUTER, modeOff: 2}, + {nodeType: NodeTypesString.FAST_GROUPS_BYPASSER, modeOff: 4}, + ]) { + for (const {restriction, afterEnable, afterDisable} of [ + {restriction: "default", afterEnable: [true, true], afterDisable: [true, false]}, + {restriction: "max one", afterEnable: [false, true], afterDisable: [false, false]}, + {restriction: "always one", afterEnable: [false, true], afterDisable: [false, true]}, + ]) { + await should(`${nodeType} enforce ${restriction} after widget adoption`, async () => { + app.graph.clear(); + const controller = LiteGraph.createNode(nodeType); + if ( + !controller || + !("refreshWidgets" in controller) || + typeof controller.refreshWidgets !== "function" + ) { + throw new Error(`${nodeType} is not registered`); + } + controller.properties.toggleRestriction = restriction; + + const nodes = [0, 500].map((x, index) => { + const node = new LGraphNode(`Member ${index}`); + app.graph.add(node); + node.pos = [x + 50, 100]; + node.mode = modeOff; + const group = new LGraphGroup(`Group ${index}`); + app.graph.add(group); + group.pos = [x, 0]; + group.size = [400, 300]; + return node; + }); + + try { + app.graph.add(controller); + controller.pos = [0, 400]; + await new Promise(requestAnimationFrame); + controller.refreshWidgets(); + expect(controller.widgets.length).toBe("group toggle count", 2); + const [first, second] = controller.widgets; + if ( + !first || + !second || + !("toggle" in first) || + typeof first.toggle !== "function" || + !("toggle" in second) || + typeof second.toggle !== "function" + ) { + throw new Error("Group toggle widgets were not created"); + } + first.toggle(); + second.toggle(); + expect(JSON.stringify(nodes.map((node) => node.mode))).toBe( + "modes after enabling two groups", + JSON.stringify(afterEnable.map((active) => (active ? 0 : modeOff))), + ); + second.toggle(); + expect(JSON.stringify(nodes.map((node) => node.mode))).toBe( + "modes after toggling the second group off", + JSON.stringify(afterDisable.map((active) => (active ? 0 : modeOff))), + ); + } finally { + app.graph.clear(); + } + }); + } + } +}); diff --git a/web/comfyui/fast_groups_muter.js b/web/comfyui/fast_groups_muter.js index 11ee58f0..2572f06d 100644 --- a/web/comfyui/fast_groups_muter.js +++ b/web/comfyui/fast_groups_muter.js @@ -323,13 +323,13 @@ class FastGroupsToggleRowWidget extends RgthreeBaseWidget { if (skipOtherNodeCheck !== true) { if (newValue && ((_b = (_a = this.node.properties) === null || _a === void 0 ? void 0 : _a[PROPERTY_RESTRICTION]) === null || _b === void 0 ? void 0 : _b.includes(" one"))) { for (const widget of this.node.widgets) { - if (widget instanceof FastGroupsToggleRowWidget) { + if ("doModeChange" in widget && typeof widget.doModeChange === "function") { widget.doModeChange(false, true); } } } else if (!newValue && ((_c = this.node.properties) === null || _c === void 0 ? void 0 : _c[PROPERTY_RESTRICTION]) === "always one") { - newValue = this.node.widgets.every((w) => !w.value || w === this); + newValue = this.node.widgets.every((w) => w === this || !("toggled" in w && w.toggled)); } } changeModeOfNodes(getGroupNodes(this.group), (newValue ? this.node.modeOn : this.node.modeOff));