From 78bd6704fe6b502cfdffd0ba3645bbe8f9646fc3 Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Tue, 22 Apr 2025 00:03:00 +1000 Subject: [PATCH] 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` --- src/LGraphNode.ts | 24 +++++++++++++----------- src/NodeSlot.ts | 4 ++-- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/LGraphNode.ts b/src/LGraphNode.ts index 16f017ef5..7f16de2e9 100644 --- a/src/LGraphNode.ts +++ b/src/LGraphNode.ts @@ -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, + }) + } } } diff --git a/src/NodeSlot.ts b/src/NodeSlot.ts index c766b7f74..8e8750618 100644 --- a/src/NodeSlot.ts +++ b/src/NodeSlot.ts @@ -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 {