-
Notifications
You must be signed in to change notification settings - Fork 490
Fix reactivity washing in refreshNodeSlots #7802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -245,17 +245,10 @@ export function useGraphNodeManager(graph: LGraph): GraphNodeManager { | |||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Update only widgets with new slot metadata, keeping other widget data intact | ||||||||||||||||||||||||||||||||||
| const updatedWidgets = currentData.widgets?.map((widget) => { | ||||||||||||||||||||||||||||||||||
| for (const widget of currentData.widgets ?? []) { | ||||||||||||||||||||||||||||||||||
| const slotInfo = slotMetadata.get(widget.name) | ||||||||||||||||||||||||||||||||||
| return slotInfo ? { ...widget, slotMetadata: slotInfo } : widget | ||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| vueNodeData.set(nodeId, { | ||||||||||||||||||||||||||||||||||
| ...currentData, | ||||||||||||||||||||||||||||||||||
| widgets: updatedWidgets, | ||||||||||||||||||||||||||||||||||
| inputs: nodeRef.inputs ? [...nodeRef.inputs] : undefined, | ||||||||||||||||||||||||||||||||||
| outputs: nodeRef.outputs ? [...nodeRef.outputs] : undefined | ||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||
| if (slotInfo) widget.slotMetadata = slotInfo | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+248
to
+251
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial LGTM - Reactivity fix is correct! The in-place mutation correctly preserves Vue reactivity by avoiding the spread operator's object reconstruction. This ensures widgets remain reactive after connections are made. 💡 Optional: Consider clearing stale slot metadataThe current code only updates widgets that have slot info. If a widget previously had a slot that was later removed (rare edge case), the old for (const widget of currentData.widgets ?? []) {
- const slotInfo = slotMetadata.get(widget.name)
- if (slotInfo) widget.slotMetadata = slotInfo
+ widget.slotMetadata = slotMetadata.get(widget.name)
}This assigns 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Extract safe data from LiteGraph node for Vue consumption | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { setActivePinia } from 'pinia' | ||
| import { createTestingPinia } from '@pinia/testing' | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import { nextTick, watch } from 'vue' | ||
|
|
||
| import { useGraphNodeManager } from '@/composables/graph/useGraphNodeManager' | ||
| import { LGraph, LGraphNode } from '@/lib/litegraph/src/litegraph' | ||
| import { NodeSlotType } from '@/lib/litegraph/src/types/globalEnums' | ||
|
|
||
| setActivePinia(createTestingPinia()) | ||
AustinMroz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| function createTestGraph() { | ||
| const graph = new LGraph() | ||
| const node = new LGraphNode('test') | ||
| node.addInput('input', 'INT') | ||
| node.addWidget('number', 'testnum', 2, () => undefined, {}) | ||
| graph.add(node) | ||
|
|
||
| const { vueNodeData } = useGraphNodeManager(graph) | ||
| const onReactivityUpdate = vi.fn() | ||
| watch(vueNodeData, onReactivityUpdate) | ||
|
|
||
| return [node, graph, onReactivityUpdate] as const | ||
| } | ||
|
Comment on lines
+12
to
+24
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Consider capturing and calling cleanup for proper teardown. The 🔎 Proposed refactor function createTestGraph() {
const graph = new LGraph()
const node = new LGraphNode('test')
node.addInput('input', 'INT')
node.addWidget('number', 'testnum', 2, () => undefined, {})
graph.add(node)
- const { vueNodeData } = useGraphNodeManager(graph)
+ const { vueNodeData, cleanup } = useGraphNodeManager(graph)
const onReactivityUpdate = vi.fn()
watch(vueNodeData, onReactivityUpdate)
- return [node, graph, onReactivityUpdate] as const
+ return [node, graph, onReactivityUpdate, cleanup] as const
}
describe('Node Reactivity', () => {
+ let cleanup: (() => void) | undefined
+
+ afterEach(() => {
+ cleanup?.()
+ })
+
it('should trigger on callback', async () => {
- const [node, , onReactivityUpdate] = createTestGraph()
+ const [node, , onReactivityUpdate, cleanupFn] = createTestGraph()
+ cleanup = cleanupFn
🤖 Prompt for AI Agents |
||
|
|
||
| describe('Node Reactivity', () => { | ||
| it('should trigger on callback', async () => { | ||
| const [node, , onReactivityUpdate] = createTestGraph() | ||
|
|
||
| node.widgets![0].callback!(2) | ||
| await nextTick() | ||
| expect(onReactivityUpdate).toHaveBeenCalledTimes(1) | ||
| }) | ||
|
|
||
| it('should remain reactive after a connection is made', async () => { | ||
| const [node, graph, onReactivityUpdate] = createTestGraph() | ||
|
|
||
| graph.trigger('node:slot-links:changed', { | ||
| nodeId: '1', | ||
| slotType: NodeSlotType.INPUT | ||
| }) | ||
AustinMroz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| await nextTick() | ||
| onReactivityUpdate.mockClear() | ||
|
|
||
| node.widgets![0].callback!(2) | ||
| await nextTick() | ||
| expect(onReactivityUpdate).toHaveBeenCalledTimes(1) | ||
| }) | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting for the future, but this is the kind of thing that could be done PRN in the context of a WidgetDataStore.