Fix context window progress display

This commit is contained in:
Fillip
2026-09-04 02:05:05 -07:00
parent 778c6c983f
commit f8a60462a2
2 changed files with 22 additions and 7 deletions
+15
View File
@@ -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/);
});
@@ -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);
});