Improve slot render stability & perf (#954)

- `draw` is now skipped for slots that should not be shown (prev. drawn
with 0 alpha)
- Fixes slot always rendered when widget not found in `node.widgets`
- Remove redundant check from `isWidgetInputSlot` - type is already
`INodeInputSlot`
This commit is contained in:
filtered
2025-04-22 00:03:00 +10:00
committed by GitHub
parent 2ad1481f02
commit 78bd6704fe
2 changed files with 15 additions and 13 deletions

View File

@@ -3493,7 +3493,8 @@ export class LGraphNode implements Positionable, IPinnable, IColorable {
return this.#getMouseOverSlot(slot) === slot
}
#isMouseOverWidget(widget: IWidget): boolean {
#isMouseOverWidget(widget: IWidget | undefined): boolean {
if (!widget) return false
return this.mouseOver?.overWidget === widget
}
@@ -3535,19 +3536,20 @@ export class LGraphNode implements Positionable, IPinnable, IColorable {
// - the mouse is over the widget
// - the slot is valid during link drop
// - the slot is connected
const showSlot = isMouseOverSlot ||
if (
isMouseOverSlot ||
isValidTarget ||
!slotInstance.isWidgetInputSlot ||
this.#isMouseOverWidget(this.getWidgetFromSlot(slotInstance)!) ||
this.#isMouseOverWidget(this.getWidgetFromSlot(slotInstance)) ||
slotInstance.isConnected()
ctx.globalAlpha = showSlot ? (isValid ? editorAlpha : 0.4 * editorAlpha) : 0
slotInstance.draw(ctx, {
colorContext,
lowQuality,
highlight,
})
) {
ctx.globalAlpha = isValid ? editorAlpha : 0.4 * editorAlpha
slotInstance.draw(ctx, {
colorContext,
lowQuality,
highlight,
})
}
}
}

View File

@@ -72,11 +72,11 @@ export function toNodeSlotClass(slot: INodeInputSlot | INodeOutputSlot): NodeInp
}
/**
* Whether this slot is an input slot and attached to a widget.
* Type guard: Whether this input slot is attached to a widget.
* @param slot The slot to check.
*/
export function isWidgetInputSlot(slot: INodeInputSlot): slot is IWidgetInputSlot {
return isINodeInputSlot(slot) && !!slot.widget
return !!slot.widget
}
export abstract class NodeSlot implements INodeSlot {