Skip to content

Commit 9ab7852

Browse files
AustinMrozDrJKL
authored andcommitted
Fix doubling of callback triggers
Callback is usually, but not always triggered when the value changes. This had two downsides: - The dynamic Combo code would usually apply twice on value change - If there was any code that also added callbacks to the widget, it would be applied multiple times. Both of these are fixed by not setting the widget change code as a callback.
1 parent e1c03ec commit 9ab7852

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/extensions/core/dynamicCombo.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import { useChainCallback } from '@/composables/functional/useChainCallback'
21
import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode'
32
import { transformInputSpecV1ToV2 } from '@/schemas/nodeDef/migration'
4-
//import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets'
53

64
import type {
75
ComboInputSpec,
@@ -34,9 +32,9 @@ function COMFY_DYNAMICCOMBO_V3(
3432
widgetName
3533
)
3634
let currentDynamicNames: string[] = []
37-
widget.callback = useChainCallback(widget.callback, (value) => {
35+
const updateWidgets = (value?: string) => {
3836
if (!node.widgets) throw new Error('Not Reachable')
39-
const newSpec = options[value]
37+
const newSpec = value ? options[value] : undefined
4038
//TODO: Calculate intersection for widgets that persist across options
4139
for (const name of currentDynamicNames) {
4240
const inputIndex = node.inputs.findIndex((input) => input.name === name)
@@ -84,7 +82,7 @@ function COMFY_DYNAMICCOMBO_V3(
8482
const addedWidgets = node.widgets.splice(startingLength)
8583
node.widgets.splice(insertionPoint, 0, ...addedWidgets)
8684
node.computeSize(node.size)
87-
})
85+
}
8886
//A little hacky, but onConfigure won't work.
8987
//It fires too late and is overly disruptive
9088
let widgetValue = widget.value
@@ -94,7 +92,7 @@ function COMFY_DYNAMICCOMBO_V3(
9492
},
9593
set(value) {
9694
widgetValue = value
97-
this.callback!(value)
95+
updateWidgets(value)
9896
}
9997
})
10098
widget.value = widgetValue

0 commit comments

Comments
 (0)