Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/core/graph/widgets/dynamicWidgets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ function dynamicComboWidget(
const newSpec = value ? options[value] : undefined

const removedInputs = remove(node.inputs, isInGroup)
for (const widget of remove(node.widgets, isInGroup)) widget.onRemove?.()

const removedWidgets = remove(node.widgets, isInGroup)
for (const widget of removedWidgets) widget.onRemove?.()

if (!newSpec) return

Expand Down Expand Up @@ -174,6 +176,18 @@ function dynamicComboWidget(
)
}
}
for (const widget of removedWidgets) {
const newMatchingWidget = addedWidgets.find((w) => w.name === widget.name)
if (!newMatchingWidget || newMatchingWidget.type !== widget.type) continue

const nameSegment = widget.name.slice(widget.name.lastIndexOf('.') + 1)
const spec =
newSpec.required?.[nameSegment] ?? newSpec.optional?.[nameSegment]
if (spec?.[1] && 'default' in spec?.[1]) continue

newMatchingWidget.value = widget.value
newMatchingWidget.callback?.(widget.value)
}
Comment on lines +179 to +190

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Address Biome noUnsafeOptionalChaining lint error on Line 186.

Biome flags 'default' in spec?.[1] because the in operator throws TypeError if its right-hand operand is undefined. While && short-circuiting makes this safe at runtime, the lint rule doesn't track that. Dropping optional chaining in favor of a direct truthy guard silences the warning and is arguably clearer:

Proposed fix
-      const spec =
-        newSpec.required?.[nameSegment] ?? newSpec.optional?.[nameSegment]
-      if (spec?.[1] && 'default' in spec?.[1]) continue
+      const spec =
+        newSpec.required?.[nameSegment] ?? newSpec.optional?.[nameSegment]
+      if (spec && spec[1] && 'default' in spec[1]) continue
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for (const widget of removedWidgets) {
const newMatchingWidget = addedWidgets.find((w) => w.name === widget.name)
if (!newMatchingWidget || newMatchingWidget.type !== widget.type) continue
const nameSegment = widget.name.slice(widget.name.lastIndexOf('.') + 1)
const spec =
newSpec.required?.[nameSegment] ?? newSpec.optional?.[nameSegment]
if (spec?.[1] && 'default' in spec?.[1]) continue
newMatchingWidget.value = widget.value
newMatchingWidget.callback?.(widget.value)
}
for (const widget of removedWidgets) {
const newMatchingWidget = addedWidgets.find((w) => w.name === widget.name)
if (!newMatchingWidget || newMatchingWidget.type !== widget.type) continue
const nameSegment = widget.name.slice(widget.name.lastIndexOf('.') + 1)
const spec =
newSpec.required?.[nameSegment] ?? newSpec.optional?.[nameSegment]
if (spec && spec[1] && 'default' in spec[1]) continue
newMatchingWidget.value = widget.value
newMatchingWidget.callback?.(widget.value)
}
🧰 Tools
🪛 Biome (2.3.13)

[error] 186-186: Unsafe usage of optional chaining.

If it short-circuits with 'undefined' the evaluation will throw TypeError here:

(lint/correctness/noUnsafeOptionalChaining)

🤖 Prompt for AI Agents
In `@src/core/graph/widgets/dynamicWidgets.ts` around lines 179 - 190, The lint
error is caused by using optional chaining with the in operator on spec?.[1];
update the guard so the right-hand operand is a plain property access guarded by
a truthy check. In the loop over removedWidgets where you compute spec from
newSpec, replace the condition `if (spec?.[1] && 'default' in spec?.[1])
continue` with a two-step truthy guard such as checking `spec && spec[1]` before
using `'default' in spec[1]` so that the in-operator never receives undefined;
this touches the block that assigns newMatchingWidget.value and calls
newMatchingWidget.callback.


node.size[1] = node.computeSize([...node.size])[1]
if (!node.graph) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ function onValueChange(this: INumericWidget, v: number) {
// Round to nearest step, accounting for offset
this.value = Math.round((v - offset) / step) * step + offset
}
if (this.options.min !== undefined && this.value < this.options.min)
this.value = this.options.min
if (this.options.max !== undefined && this.value > this.options.max)
this.value = this.options.max
}

export const _for_testing = {
Expand Down
Loading