From f8a60462a2cfe967c8fb4dab26e4dc6bd27d9fee Mon Sep 17 00:00:00 2001 From: Fillip Date: Fri, 4 Sep 2026 02:05:05 -0700 Subject: [PATCH] Fix context window progress display --- tests/test_context_window_progress.mjs | 15 +++++++++++++++ web/nodes/ksamplers/FL_KsamplerContextWindow.js | 14 +++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 tests/test_context_window_progress.mjs diff --git a/tests/test_context_window_progress.mjs b/tests/test_context_window_progress.mjs new file mode 100644 index 0000000..08d2c0a --- /dev/null +++ b/tests/test_context_window_progress.mjs @@ -0,0 +1,15 @@ +import assert from "node:assert/strict"; +import { readFile } from "node:fs/promises"; +import test from "node:test"; + +const source = await readFile( + new URL("../web/nodes/ksamplers/FL_KsamplerContextWindow.js", import.meta.url), + "utf8", +); + +test("context-window progress uses stable string node keys", () => { + assert.match(source, /const nodeKey = \(value\) => String\(value\);/); + assert.match(source, /INSTANCES\.set\(nodeKey\(node\.id\), inst\);/); + assert.match(source, /INSTANCES\.get\(nodeKey\(detail\.node\)\)/); + assert.doesNotMatch(source, /parseInt\(detail\.node/); +}); diff --git a/web/nodes/ksamplers/FL_KsamplerContextWindow.js b/web/nodes/ksamplers/FL_KsamplerContextWindow.js index b437bf5..8a72689 100644 --- a/web/nodes/ksamplers/FL_KsamplerContextWindow.js +++ b/web/nodes/ksamplers/FL_KsamplerContextWindow.js @@ -140,6 +140,7 @@ class ContextWindowProgressWidget { } const INSTANCES = new Map(); +const nodeKey = (value) => String(value); app.registerExtension({ name: "ComfyUI.FL_KsamplerContextWindow", @@ -167,14 +168,15 @@ app.registerExtension({ setTimeout(() => { const inst = new ContextWindowProgressWidget({ container }); - INSTANCES.set(node.id, inst); + INSTANCES.set(nodeKey(node.id), inst); }, 50); widget.onRemove = () => { - const inst = INSTANCES.get(node.id); + const key = nodeKey(node.id); + const inst = INSTANCES.get(key); if (inst) { inst.dispose(); - INSTANCES.delete(node.id); + INSTANCES.delete(key); } }; }, @@ -183,16 +185,14 @@ app.registerExtension({ api.addEventListener("executing", (event) => { const detail = event.detail; if (!detail || !detail.node) return; - const nodeId = parseInt(detail.node, 10); - const inst = INSTANCES.get(nodeId); + const inst = INSTANCES.get(nodeKey(detail.node)); if (inst) inst.reset(); }); api.addEventListener("fl_context_window_progress", (event) => { const detail = event.detail; if (!detail) return; - const nodeId = parseInt(detail.node, 10); - const inst = INSTANCES.get(nodeId); + const inst = INSTANCES.get(nodeKey(detail.node)); if (!inst) return; inst.update(detail); });