Skip to content

Commit be22ec1

Browse files
committed
Fix infinite callback loop and equality check
1 parent bd7f3cb commit be22ec1

File tree

3 files changed

+38
-31
lines changed

3 files changed

+38
-31
lines changed

src/components/graph/vueWidgets/WidgetTextarea.vue

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import Textarea from 'primevue/textarea'
1515
import { computed } from 'vue'
1616
17-
import { useWidgetValue } from '@/composables/graph/useWidgetValue'
17+
import { useStringWidgetValue } from '@/composables/graph/useWidgetValue'
1818
import type { SimplifiedWidget } from '@/types/simplifiedWidget'
1919
import {
2020
INPUT_EXCLUDED_PROPS,
@@ -32,12 +32,11 @@ const emit = defineEmits<{
3232
}>()
3333
3434
// Use the composable for consistent widget value handling
35-
const { localValue, onChange } = useWidgetValue({
36-
widget: props.widget,
37-
modelValue: props.modelValue,
38-
defaultValue: '',
35+
const { localValue, onChange } = useStringWidgetValue(
36+
props.widget,
37+
props.modelValue,
3938
emit
40-
})
39+
)
4140
4241
const filteredProps = computed(() =>
4342
filterWidgetProps(props.widget.options, INPUT_EXCLUDED_PROPS)

src/composables/graph/useGraphNodeManager.ts

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -270,29 +270,42 @@ export const useGraphNodeManager = (graph: LGraph): GraphNodeManager => {
270270
originalCallback: ((value: unknown) => void) | undefined,
271271
nodeId: string
272272
) => {
273+
let updateInProgress = false
274+
273275
return (value: unknown) => {
274-
// 1. Update the widget value in LiteGraph (critical for LiteGraph state)
275-
// Validate that the value is of an acceptable type
276-
if (
277-
value !== null &&
278-
value !== undefined &&
279-
typeof value !== 'string' &&
280-
typeof value !== 'number' &&
281-
typeof value !== 'boolean' &&
282-
typeof value !== 'object'
283-
) {
284-
console.warn(`Invalid widget value type: ${typeof value}`)
285-
return
286-
}
287-
widget.value = value
276+
// Prevent circular callbacks - bulletproof recursion guard
277+
if (updateInProgress) return
278+
updateInProgress = true
288279

289-
// 2. Call the original callback if it exists
290-
if (originalCallback) {
291-
originalCallback.call(widget, value)
292-
}
280+
try {
281+
// 1. Update the widget value in LiteGraph (critical for LiteGraph state)
282+
// Validate that the value is of an acceptable type
283+
if (
284+
value !== null &&
285+
value !== undefined &&
286+
typeof value !== 'string' &&
287+
typeof value !== 'number' &&
288+
typeof value !== 'boolean' &&
289+
typeof value !== 'object'
290+
) {
291+
console.warn(`Invalid widget value type: ${typeof value}`)
292+
updateInProgress = false
293+
return
294+
}
295+
296+
// Always update widget.value to ensure sync
297+
widget.value = value
293298

294-
// 3. Update Vue state to maintain synchronization
295-
updateVueWidgetState(nodeId, widget.name, value)
299+
// 2. Call the original callback if it exists
300+
if (originalCallback) {
301+
originalCallback.call(widget, value)
302+
}
303+
304+
// 3. Update Vue state to maintain synchronization
305+
updateVueWidgetState(nodeId, widget.name, value)
306+
} finally {
307+
updateInProgress = false
308+
}
296309
}
297310
}
298311

src/composables/graph/useWidgetValue.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ export function useWidgetValue<T extends WidgetValue = WidgetValue, U = T>({
8181

8282
// 2. Emit to parent component
8383
emit('update:modelValue', processedValue)
84-
85-
// 3. Call LiteGraph callback to update authoritative state
86-
if (widget.callback) {
87-
widget.callback(processedValue)
88-
}
8984
}
9085

9186
// Watch for external updates from LiteGraph

0 commit comments

Comments
 (0)