Skip to content

Commit c9da8b2

Browse files
authored
Fix: Allow uncoloring Vue Nodes (#5991)
## Summary Fixes an issue where trying to uncolor a node broke the vue color syncing. ## Changes - **What**: Changes litegraph property removal from `delete` to `= undefined` ## Screenshots ### Before https://github.com/user-attachments/assets/81a1ad40-ba5d-4dec-8f90-5b61eb804a16 ### After https://github.com/user-attachments/assets/459d2d15-c728-49d2-abd9-6e255e5383e5 ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-5991-Fix-Allow-uncoloring-Vue-Nodes-2876d73d365081f4a74fc9fa423aae1c) by [Unito](https://www.unito.io)
1 parent 9f0fa72 commit c9da8b2

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

src/lib/litegraph/src/LGraphNode.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,8 @@ export class LGraphNode
344344
/** @inheritdoc {@link IColorable.setColorOption} */
345345
setColorOption(colorOption: ColorOption | null): void {
346346
if (colorOption == null) {
347-
delete this.color
348-
delete this.bgcolor
347+
this.color = undefined
348+
this.bgcolor = undefined
349349
} else {
350350
this.color = colorOption.color
351351
this.bgcolor = colorOption.bgcolor
@@ -495,7 +495,7 @@ export class LGraphNode
495495
set shape(v: RenderShape | 'default' | 'box' | 'round' | 'circle' | 'card') {
496496
switch (v) {
497497
case 'default':
498-
delete this._shape
498+
this._shape = undefined
499499
break
500500
case 'box':
501501
this._shape = RenderShape.BOX
@@ -943,7 +943,7 @@ export class LGraphNode
943943
}
944944

945945
// @ts-expect-error Exceptional case: id is removed so that the graph can assign a new one on add.
946-
delete data.id
946+
data.id = undefined
947947

948948
if (LiteGraph.use_uuids) data.id = LiteGraph.uuidv4()
949949

@@ -1948,7 +1948,7 @@ export class LGraphNode
19481948
for (const input of this.inputs) {
19491949
if (input._widget === widget) {
19501950
input._widget = undefined
1951-
delete input.widget
1951+
input.widget = undefined
19521952
}
19531953
}
19541954
}
@@ -2857,7 +2857,7 @@ export class LGraphNode
28572857
const reroutes = LLink.getReroutes(graph, link)
28582858
for (const reroute of reroutes) {
28592859
reroute.linkIds.add(link.id)
2860-
if (reroute.floating) delete reroute.floating
2860+
if (reroute.floating) reroute.floating = undefined
28612861
reroute._dragging = undefined
28622862
}
28632863

@@ -2947,7 +2947,7 @@ export class LGraphNode
29472947

29482948
reroute.floatingLinkIds.add(link.id)
29492949
link.parentId = reroute.id
2950-
delete parentReroute.floating
2950+
parentReroute.floating = undefined
29512951
return reroute
29522952
}
29532953

src/lib/litegraph/src/LGraphNodeProperties.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,12 @@ export class LGraphNodeProperties {
132132
oldValue: any,
133133
newValue: any
134134
): void {
135-
if (oldValue !== newValue && this.node.graph) {
136-
this.node.graph.trigger('node:property:changed', {
137-
nodeId: this.node.id,
138-
property: propertyPath,
139-
oldValue,
140-
newValue
141-
})
142-
}
135+
this.node.graph?.trigger('node:property:changed', {
136+
nodeId: this.node.id,
137+
property: propertyPath,
138+
oldValue,
139+
newValue
140+
})
143141
}
144142

145143
/**

tests-ui/tests/litegraph/core/LGraphNodeProperties.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ describe('LGraphNodeProperties', () => {
4646
})
4747
})
4848

49-
it("should not emit events when value doesn't change", () => {
49+
it('should emit event when value is set to the same value', () => {
5050
new LGraphNodeProperties(mockNode)
5151

5252
mockNode.title = 'Test Node' // Same value as original
5353

54-
expect(mockGraph.trigger).toHaveBeenCalledTimes(0)
54+
expect(mockGraph.trigger).toHaveBeenCalledTimes(1)
5555
})
5656

5757
it('should not emit events when node has no graph', () => {

0 commit comments

Comments
 (0)