Skip to content

Fix automatic dynamic widget removal corrupting "create DICT" nodes (#65) - #66

Merged
StableLlama merged 1 commit into
mainfrom
fix_65
Nov 3, 2026
Merged

StableLlama merged 1 commit into
mainfrom
fix_65

Conversation

@StableLlama

Copy link
Copy Markdown
Owner

Problem

Clearing an empty dynamic input pair (e.g. key_0/value_0 of create DICT)
while later pairs still hold values corrupts the node: the widgets disappear,
the remaining values are not moved up into the right slots, a connected input
link ends up next to the wrong widget row, and the node returns {} even
though a valid pair is still configured.

Fixes #65

Root cause

removeWidgetForInput() in web/js/dynamicnode.js removed the widget with a
plain node.widgets.splice(). ComfyUI keeps widget values in a per-node store
keyed by widget name, and only node.removeWidget() deletes that entry. The
splice left the removed key_0/value_0 entries behind, so the subsequent
renumberDynamicInputs() could rename the inputs but not the widgets - the
BaseWidget.name setter found the new id still occupied and kept the old name.

That desync caused both symptoms:

  • the prompt is built from the widget names, so ComfyUI sent key_1..value_2;
    DictCreate.create() iterates from key_0 and therefore returned {}
  • input.widget.name pointed at a widget that no longer exists, so the link
    was rendered next to the wrong row

Change

Remove the widget via node.removeWidget(), with the previous array splice kept
as a fallback for older litegraph builds that lack the method. Only
web/js/dynamicnode.js is touched.

Verification

Reproduced and re-tested in a live ComfyUI 0.43 instance (frontend 1.57.4) by
scripting the exact sequence from the issue and inspecting node.inputs,
node.widgets, the link store and app.graphToPrompt().

Before the fix (clearing key_0/value_0 with key_1="otherkey" wired):

inputs : key_0, value_0(link), key_1, value_1
widgets: key_1="otherkey", value_1, key_2, value_2 <- not renumbered
prompt : {key_1:"otherkey", ...} -> node outputs {}

After the fix:

inputs : key_0, value_0(link), key_1, value_1
widgets: key_0="otherkey", value_0, key_1, value_1
prompt : {key_0:"otherkey", value_0:"", key_1:"", value_1:""} -> {"otherkey": <wired value>}

Also checked clearing a middle pair and refilling the placeholder pair
afterwards: names stay contiguous from 0 and inputs/widgets remain in sync.
node --check web/js/dynamicnode.js passes; the change is JS-only, so the
Python test suite is unaffected.

Removing an empty dynamic input pair spliced node.widgets directly, which
left the old entries in ComfyUI's widget value store. renumberDynamicInputs
then renamed the inputs, but renaming the widgets silently failed because
the target id was still taken by the orphaned entry. Input names and widget
names drifted apart: the prompt was built from the stale widget names
(key_1..value_2), so DictCreate.create() never found key_0 and returned {},
and the connected input link was drawn next to the wrong widget row.

Remove widgets through node.removeWidget() so the store entry is deleted
too, falling back to an array splice on older litegraph builds.

Verified in ComfyUI 0.43 (frontend 1.57.4): clearing a pair now keeps
inputs and widgets in sync, the link stays on its own row and the node
returns the remaining pairs.
@StableLlama
StableLlama merged commit 7716cad into main Nov 3, 2026
5 checks passed
@StableLlama
StableLlama deleted the fix_65 branch November 3, 2026 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

automatic dynamic widget removal can corrupt "create DICT" node

1 participant