Repository navigation
feat: add Nodes 2.0 alignment tools - #9750
benceruleanlu wants to merge 1 commit into
Conversation
🎨 Storybook: ✅ Built — View Storybook |
🎭 Playwright: ✅ 561 passed, 0 failed · 1 flaky📊 Browser Reports
|
📦 Bundle: 4.57 MB gzip 🔴 +2.55 kBDetailsSummary
Category Glance App Entry Points — 17.7 kB (baseline 17.7 kB) • ⚪ 0 BMain entry bundles and manifests
Status: 1 added / 1 removed Graph Workspace — 980 kB (baseline 972 kB) • 🔴 +7.36 kBGraph editor runtime, canvas, workflow orchestration
Status: 1 added / 1 removed Views & Navigation — 72.5 kB (baseline 72.5 kB) • ⚪ 0 BTop-level views, pages, and routed surfaces
Status: 9 added / 9 removed Panels & Settings — 438 kB (baseline 438 kB) • ⚪ 0 BConfiguration panels, inspectors, and settings screens
Status: 10 added / 10 removed User & Accounts — 16.1 kB (baseline 16.1 kB) • ⚪ 0 BAuthentication, profile, and account management bundles
Status: 5 added / 5 removed Editors & Dialogs — 78.3 kB (baseline 78.3 kB) • ⚪ 0 BModals, dialogs, drawers, and in-app editors
Status: 2 added / 2 removed UI Components — 56.7 kB (baseline 56.7 kB) • ⚪ 0 BReusable component library chunks
Status: 5 added / 5 removed Data & Services — 2.78 MB (baseline 2.77 MB) • 🔴 +2.9 kBStores, services, APIs, and repositories
Status: 14 added / 14 removed Utilities & Hooks — 56.8 kB (baseline 56.8 kB) • ⚪ 0 BHelpers, composables, and utility bundles
Status: 13 added / 13 removed Vendor & Third-Party — 8.9 MB (baseline 8.9 MB) • ⚪ 0 BExternal libraries and shared vendor chunks
Other — 8.04 MB (baseline 8.04 MB) • 🔴 +404 BBundles that do not match a named category
Status: 55 added / 55 removed |
📝 WalkthroughWalkthroughAdds node alignment snapping functionality to canvas node dragging, including center-alignment modes, context menu integration, visual alignment guides, and a configurable "Align nodes while dragging" setting with comprehensive test coverage. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Canvas as Canvas/VueNodes
participant useNodeDrag
participant Snap as resolveNodeAlignmentSnap
participant LayoutStore as LayoutStore<br/>(vueDragSnapGuides)
participant LGraphCanvas
User->>Canvas: Start pointer drag on selection
Canvas->>useNodeDrag: startDrag()
useNodeDrag->>useNodeDrag: Compute draggedSelectionBounds<br/>& candidateBounds
User->>Canvas: Move pointer (drag)
Canvas->>useNodeDrag: handleDrag(dx, dy)
useNodeDrag->>Snap: maybeResolveAlignmentSnap(delta)
Snap->>Snap: Match edges/centers vs candidates<br/>within threshold
Snap-->>useNodeDrag: Return {delta, guides}
useNodeDrag->>LayoutStore: updateDragSnapGuides(guides)
LayoutStore-->>useNodeDrag: vueDragSnapGuides updated
Canvas->>LGraphCanvas: Render frame
LGraphCanvas->>LGraphCanvas: _drawVueDragAlignmentGuides()
LGraphCanvas-->>User: Display alignment guides
User->>Canvas: Release pointer
Canvas->>useNodeDrag: endDrag()
useNodeDrag->>LayoutStore: Clear vueDragSnapGuides
useNodeDrag->>Canvas: Apply snapped positions
Canvas-->>User: Nodes aligned/snapped to position
sequenceDiagram
participant User
participant Node as Vue Node
participant useMoreOptionsMenu
participant useSelectionMenuOptions as useSelectionMenuOptions<br/>(getAlignmentOptions)
participant Menu as Context Menu
User->>Node: Right-click on node
Node->>useMoreOptionsMenu: showNodeOptions(..., 'contextmenu')
useMoreOptionsMenu->>useMoreOptionsMenu: Set nodeOptionsTriggerSource<br/>= 'contextmenu'
useMoreOptionsMenu->>useSelectionMenuOptions: Check selectedNodes.length >= 2?
alt Two or more nodes selected
useSelectionMenuOptions->>useSelectionMenuOptions: getAlignmentOptions(count)
useSelectionMenuOptions-->>useMoreOptionsMenu: ["Align Selected To", ...]
useMoreOptionsMenu->>useMoreOptionsMenu: Push alignment options
end
useMoreOptionsMenu-->>Menu: Display menu items
Menu-->>User: Show "Align Selected To" option
User->>Menu: Select alignment direction
Menu->>useNodeArrangement: applyAlign(direction)
useNodeArrangement-->>User: Nodes aligned
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
⚡ Performance Report
Raw data{
"timestamp": "2026-03-11T19:12:57.331Z",
"gitSha": "9fac72aae4733e7f8d165fb8a9acf8a0b39a72e9",
"branch": "bl/nodes-2-alignment-snapping",
"measurements": [
{
"name": "canvas-idle",
"durationMs": 2023.1229999999982,
"styleRecalcs": 124,
"styleRecalcDurationMs": 31.409,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 556.4929999999999,
"heapDeltaBytes": -4688380
},
{
"name": "canvas-idle",
"durationMs": 2037.4820000000113,
"styleRecalcs": 124,
"styleRecalcDurationMs": 31.019,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 518.39,
"heapDeltaBytes": 2767020
},
{
"name": "canvas-idle",
"durationMs": 2033.9269999999487,
"styleRecalcs": 125,
"styleRecalcDurationMs": 35.802,
"layouts": 1,
"layoutDurationMs": 0.21199999999999994,
"taskDurationMs": 533.832,
"heapDeltaBytes": 3075460
},
{
"name": "canvas-mouse-sweep",
"durationMs": 1891.8370000000095,
"styleRecalcs": 176,
"styleRecalcDurationMs": 59.503,
"layouts": 12,
"layoutDurationMs": 4.118,
"taskDurationMs": 909.759,
"heapDeltaBytes": 2416952
},
{
"name": "canvas-mouse-sweep",
"durationMs": 2045.6479999999715,
"styleRecalcs": 183,
"styleRecalcDurationMs": 59.669,
"layouts": 12,
"layoutDurationMs": 3.471,
"taskDurationMs": 1112.265,
"heapDeltaBytes": -4088208
},
{
"name": "canvas-mouse-sweep",
"durationMs": 2027.5460000000294,
"styleRecalcs": 183,
"styleRecalcDurationMs": 66.68199999999999,
"layouts": 12,
"layoutDurationMs": 4.184,
"taskDurationMs": 1095.882,
"heapDeltaBytes": 3483984
},
{
"name": "dom-widget-clipping",
"durationMs": 631.4960000000269,
"styleRecalcs": 44,
"styleRecalcDurationMs": 18.703999999999997,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 406.47099999999995,
"heapDeltaBytes": 13639628
},
{
"name": "dom-widget-clipping",
"durationMs": 595.1809999999682,
"styleRecalcs": 43,
"styleRecalcDurationMs": 15.154999999999998,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 387.1739999999999,
"heapDeltaBytes": 13523648
},
{
"name": "dom-widget-clipping",
"durationMs": 622.9170000000295,
"styleRecalcs": 45,
"styleRecalcDurationMs": 15.978,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 412.606,
"heapDeltaBytes": 13009964
},
{
"name": "subgraph-dom-widget-clipping",
"durationMs": 649.1609999999923,
"styleRecalcs": 77,
"styleRecalcDurationMs": 18.674000000000003,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 450.35800000000006,
"heapDeltaBytes": -4258816
},
{
"name": "subgraph-dom-widget-clipping",
"durationMs": 639.1079999999647,
"styleRecalcs": 76,
"styleRecalcDurationMs": 18.037999999999997,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 458.077,
"heapDeltaBytes": -4151040
},
{
"name": "subgraph-dom-widget-clipping",
"durationMs": 644.9570000000335,
"styleRecalcs": 77,
"styleRecalcDurationMs": 19.842000000000006,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 465.54499999999996,
"heapDeltaBytes": -2934112
},
{
"name": "subgraph-idle",
"durationMs": 2004.4819999999959,
"styleRecalcs": 121,
"styleRecalcDurationMs": 31.035,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 507.994,
"heapDeltaBytes": 2361932
},
{
"name": "subgraph-idle",
"durationMs": 1999.21599999999,
"styleRecalcs": 121,
"styleRecalcDurationMs": 30.297000000000004,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 500.9359999999999,
"heapDeltaBytes": 1576472
},
{
"name": "subgraph-idle",
"durationMs": 2001.6170000000102,
"styleRecalcs": 120,
"styleRecalcDurationMs": 29.851000000000003,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 514.017,
"heapDeltaBytes": 2356640
},
{
"name": "subgraph-mouse-sweep",
"durationMs": 1728.6149999999907,
"styleRecalcs": 157,
"styleRecalcDurationMs": 52.11600000000001,
"layouts": 16,
"layoutDurationMs": 4.572,
"taskDurationMs": 825.9920000000001,
"heapDeltaBytes": -6540564
},
{
"name": "subgraph-mouse-sweep",
"durationMs": 2001.1690000000044,
"styleRecalcs": 173,
"styleRecalcDurationMs": 63.887,
"layouts": 16,
"layoutDurationMs": 4.7299999999999995,
"taskDurationMs": 1082.854,
"heapDeltaBytes": 93200
},
{
"name": "subgraph-mouse-sweep",
"durationMs": 1762.6089999999976,
"styleRecalcs": 159,
"styleRecalcDurationMs": 55.782999999999994,
"layouts": 16,
"layoutDurationMs": 4.881999999999999,
"taskDurationMs": 843.533,
"heapDeltaBytes": -52176
}
]
} |
There was a problem hiding this comment.
Actionable comments posted: 4
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/lib/litegraph/src/LGraphCanvas.ts (1)
1071-1085:⚠️ Potential issue | 🟠 MajorReplace type assertions with a dedicated direction mapping function and expose center-alignment actions in the context menus.
Both
onNodeAlignandonGroupAlignusevalue.toLowerCase() as ArrangementDirectionto convert menu labels to enum values. This violates the guideline forsrc/lib/litegraph/**/*.{ts,tsx}to avoid type assertions. The mapping is also fragile:Horizontal Centerbecomeshorizontal centerrather thanhorizontal-center. More critically, the menus only offer Top/Bottom/Left/Right, leavinghorizontal-centerandvertical-centerunreachable despite being implemented inalignNodes.Add the missing menu options and replace the assertion with an explicit mapping function:
Suggested direction
+function getArrangementDirection( + label: string +): ArrangementDirection | undefined { + switch (label) { + case 'Top': + return 'top' + case 'Bottom': + return 'bottom' + case 'Left': + return 'left' + case 'Right': + return 'right' + case 'Horizontal Center': + return 'horizontal-center' + case 'Vertical Center': + return 'vertical-center' + default: + return undefined + } +} - new LiteGraph.ContextMenu(['Top', 'Bottom', 'Left', 'Right'], { + new LiteGraph.ContextMenu( + [ + 'Top', + 'Bottom', + 'Left', + 'Right', + 'Horizontal Center', + 'Vertical Center' + ], + { event, callback: inner_clicked, parentMenu: prev_menu - }) + } + ) function inner_clicked(value: string) { + const direction = getArrangementDirection(value) + if (!direction) return const newPositions = alignNodes( Object.values(LGraphCanvas.active_canvas.selected_nodes), - value.toLowerCase() as ArrangementDirection, + direction, node )Apply the same mapping in
onGroupAlign.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/lib/litegraph/src/LGraphCanvas.ts` around lines 1071 - 1085, The context menu currently constructs labels ['Top','Bottom','Left','Right'] and casts value.toLowerCase() as ArrangementDirection in inner_clicked; instead add the missing center options (e.g., 'Horizontal Center' and 'Vertical Center') to the ContextMenu labels and replace the type assertion with a small explicit mapping function (e.g., mapLabelToArrangementDirection) that converts menu label strings ('Top','Bottom','Left','Right','Horizontal Center','Vertical Center') into the correct ArrangementDirection values used by alignNodes; update inner_clicked (and do the same in onGroupAlign) to call mapLabelToArrangementDirection(value) and pass that result to alignNodes before calling LGraphCanvas.active_canvas.repositionNodesVueMode(newPositions) and setDirty.
🧹 Nitpick comments (4)
src/components/rightSidePanel/settings/TabGlobalSettings.vue (1)
169-173: Disable or hide this switch when Nodes 2.0 is off.This toggle only affects Vue-node dragging, so when
nodes2Enabledis false the quick setting is effectively a no-op. Disabling it here would make the dependency clear and avoid a confusing control state.♻️ Possible tweak
<FieldSwitch v-model="alignNodesWhileDragging" :label="t('rightSidePanel.globalSettings.alignNodesWhileDragging')" :tooltip="t('settings.Comfy_Canvas_AlignNodesWhileDragging.tooltip')" + :disabled="!nodes2Enabled" />🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/rightSidePanel/settings/TabGlobalSettings.vue` around lines 169 - 173, The FieldSwitch controlling alignNodesWhileDragging should be disabled or hidden when nodes2Enabled is false because it has no effect without Nodes 2.0; update the template around the FieldSwitch (symbol: FieldSwitch, model: alignNodesWhileDragging) to either add a reactive :disabled="!nodes2Enabled" binding and an explanatory tooltip or wrap it with v-if="nodes2Enabled" (or show a disabled state with a secondary tooltip referencing nodes2Enabled) so the control is not actionable when nodes2Enabled is off.src/composables/graph/useMoreOptionsMenu.test.ts (1)
65-71: Make the mocked alignment options depend onselectedNodeCount.
getAlignmentOptionsnow takesselectedNodeCount, but this mock ignores the argument and always returns the align option. That means this test still passes even ifuseMoreOptionsMenu()stops forwarding the count or always forwards the wrong value.🧪 Tighten the mock
vi.mock('@/composables/graph/useSelectionMenuOptions', () => ({ useSelectionMenuOptions: () => ({ getBasicSelectionOptions: () => [{ label: 'Rename' }], getMultipleNodesOptions: () => [{ label: 'Frame Nodes' }], getSubgraphOptions: () => [], - getAlignmentOptions: () => [{ label: 'Align Selected To' }] + getAlignmentOptions: (selectedNodeCount: number) => { + const options = [] + + if (selectedNodeCount >= 2) { + options.push({ label: 'Align Selected To' }) + } + if (selectedNodeCount >= 3) { + options.push({ label: 'Distribute Nodes' }) + } + + return options + } }) }))As per coding guidelines: "Do not write tests that just test the mocks; ensure tests fail when code behaves unexpectedly."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/composables/graph/useMoreOptionsMenu.test.ts` around lines 65 - 71, The mock for useSelectionMenuOptions ignores the selectedNodeCount so tests won't catch mis-forwarding; update the vi.mock to make getAlignmentOptions accept a selectedNodeCount parameter and return the alignment option only when the count indicates multiple nodes (e.g., selectedNodeCount > 1 or >= 2) and return [] otherwise, so useMoreOptionsMenu() must forward the correct count to pass the test.src/composables/graph/useSelectionMenuOptions.test.ts (1)
85-104: Add the below-threshold boundary case.The new branching here is
>= 2/>= 3, but these tests only cover the enabled states. An explicitgetAlignmentOptions(0)orgetAlignmentOptions(1)assertion would lock down the case that should return no alignment actions.🧪 Suggested follow-up test
+ it('returns no alignment options for fewer than two selected nodes', () => { + const { getAlignmentOptions } = useSelectionMenuOptions() + + expect(getAlignmentOptions(0)).toEqual([]) + expect(getAlignmentOptions(1)).toEqual([]) + }) + it('returns align options for two selected nodes', () => { const { getAlignmentOptions } = useSelectionMenuOptions()🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/composables/graph/useSelectionMenuOptions.test.ts` around lines 85 - 104, Add a boundary test that asserts getAlignmentOptions returns no alignment actions for below-threshold selections: call getAlignmentOptions(0) and getAlignmentOptions(1) and expect options.map(option => option.label) to be an empty array (or otherwise assert no alignment/distribute labels). Place these assertions alongside the existing tests for two and three selected nodes (same test suite using useSelectionMenuOptions and the getAlignmentOptions helper) to lock down the >=2 / >=3 branching.src/composables/graph/contextMenuConverter.ts (1)
48-49: Duplicate entries inCORE_MENU_ITEMSSet.
'Align Selected To'and'Distribute Nodes'appear twice in the Set—once in the "Structure operations" section (lines 48-49) and again in the "Selection and alignment" section (lines 75-76). While Sets deduplicate automatically so this is not a bug, the redundancy is confusing.Consider keeping them in only one location for clarity.
Also applies to: 75-76
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/composables/graph/contextMenuConverter.ts` around lines 48 - 49, CORE_MENU_ITEMS contains duplicate string entries ('Align Selected To' and 'Distribute Nodes') across the "Structure operations" and "Selection and alignment" sections; remove the duplicates so each label appears only once in the Set (e.g., keep them in the more semantically appropriate "Selection and alignment" section) by deleting the redundant entries from the other section while leaving the Set declaration and order otherwise unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/renderer/core/layout/store/layoutStore.ts`:
- Around line 141-142: When reinitializing the layout store in
initializeFromLiteGraph(), also reset the singleton's Vue drag guide state by
clearing vueDragSnapGuides and resetting isDraggingVueNodes so stale guides
aren't rendered; update initializeFromLiteGraph() to set vueDragSnapGuides.value
= [] (and isDraggingVueNodes.value = false if appropriate) so
_drawVueDragAlignmentGuides() has no leftover data to render after a workflow
reload or mode switch.
In `@src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts`:
- Around line 103-106: The test's layoutStore mock is missing vueDragSnapGuides
which causes cleanupDragState() (in useNodePointerInteractions.cleanupDragState)
to assign to undefined; update the mock object used in the tests to include
vueDragSnapGuides: ref([]) (and import/ref from 'vue' in the test if not already
present) so layoutStore.vueDragSnapGuides.value can be safely assigned during
drag end/cancel/unmount flows.
In `@src/renderer/extensions/vueNodes/layout/useNodeDrag.ts`:
- Around line 67-70: Prepare draggedSelectionBounds as before but only compute
alignmentCandidateBounds when the opt-in setting
Comfy.Canvas.AlignNodesWhileDragging is enabled: keep creating selectedNodes
(from toValue(selectedNodeIds) and nodeId) and call
getDraggedSelectionBounds(selectedNodes) unconditionally, but wrap the call to
getAlignmentCandidateBounds(selectedNodes) (and assignment to
alignmentCandidateBounds) in an if-check that reads the
Comfy.Canvas.AlignNodesWhileDragging setting so you avoid walking the node map
when alignment is disabled; apply the same conditional guard around the
analogous calls found later in the file (the other block noted in the review).
- Around line 67-75: The code currently mutates selectedNodes by calling
selectedNodes.add(nodeId) before checking membership, so
isDraggedNodeInSelection is always true; fix by determining whether the dragged
node is in the original selection first (compute isDraggedNodeInSelection =
toValue(selectedNodeIds).has(nodeId) or check membership against a Set created
from toValue(selectedNodeIds)), then add nodeId to selectedNodes and call
getDraggedSelectionBounds, getAlignmentCandidateBounds, updateDragSnapGuides;
apply the same change to the other similar blocks referenced around the
isDraggedNodeInSelection usage (the blocks around lines 77-83 and 95-100) to
preserve original selection membership before mutation.
---
Outside diff comments:
In `@src/lib/litegraph/src/LGraphCanvas.ts`:
- Around line 1071-1085: The context menu currently constructs labels
['Top','Bottom','Left','Right'] and casts value.toLowerCase() as
ArrangementDirection in inner_clicked; instead add the missing center options
(e.g., 'Horizontal Center' and 'Vertical Center') to the ContextMenu labels and
replace the type assertion with a small explicit mapping function (e.g.,
mapLabelToArrangementDirection) that converts menu label strings
('Top','Bottom','Left','Right','Horizontal Center','Vertical Center') into the
correct ArrangementDirection values used by alignNodes; update inner_clicked
(and do the same in onGroupAlign) to call mapLabelToArrangementDirection(value)
and pass that result to alignNodes before calling
LGraphCanvas.active_canvas.repositionNodesVueMode(newPositions) and setDirty.
---
Nitpick comments:
In `@src/components/rightSidePanel/settings/TabGlobalSettings.vue`:
- Around line 169-173: The FieldSwitch controlling alignNodesWhileDragging
should be disabled or hidden when nodes2Enabled is false because it has no
effect without Nodes 2.0; update the template around the FieldSwitch (symbol:
FieldSwitch, model: alignNodesWhileDragging) to either add a reactive
:disabled="!nodes2Enabled" binding and an explanatory tooltip or wrap it with
v-if="nodes2Enabled" (or show a disabled state with a secondary tooltip
referencing nodes2Enabled) so the control is not actionable when nodes2Enabled
is off.
In `@src/composables/graph/contextMenuConverter.ts`:
- Around line 48-49: CORE_MENU_ITEMS contains duplicate string entries ('Align
Selected To' and 'Distribute Nodes') across the "Structure operations" and
"Selection and alignment" sections; remove the duplicates so each label appears
only once in the Set (e.g., keep them in the more semantically appropriate
"Selection and alignment" section) by deleting the redundant entries from the
other section while leaving the Set declaration and order otherwise unchanged.
In `@src/composables/graph/useMoreOptionsMenu.test.ts`:
- Around line 65-71: The mock for useSelectionMenuOptions ignores the
selectedNodeCount so tests won't catch mis-forwarding; update the vi.mock to
make getAlignmentOptions accept a selectedNodeCount parameter and return the
alignment option only when the count indicates multiple nodes (e.g.,
selectedNodeCount > 1 or >= 2) and return [] otherwise, so useMoreOptionsMenu()
must forward the correct count to pass the test.
In `@src/composables/graph/useSelectionMenuOptions.test.ts`:
- Around line 85-104: Add a boundary test that asserts getAlignmentOptions
returns no alignment actions for below-threshold selections: call
getAlignmentOptions(0) and getAlignmentOptions(1) and expect options.map(option
=> option.label) to be an empty array (or otherwise assert no
alignment/distribute labels). Place these assertions alongside the existing
tests for two and three selected nodes (same test suite using
useSelectionMenuOptions and the getAlignmentOptions helper) to lock down the >=2
/ >=3 branching.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: e9a80bff-f2d9-4388-9d4c-5c60330bd8ac
📒 Files selected for processing (24)
browser_tests/tests/vueNodes/interactions/node/alignment.spec.tssrc/components/graph/selectionToolbox/NodeOptionsButton.vuesrc/components/rightSidePanel/settings/TabGlobalSettings.vuesrc/composables/graph/contextMenuConverter.tssrc/composables/graph/useMoreOptionsMenu.test.tssrc/composables/graph/useMoreOptionsMenu.tssrc/composables/graph/useNodeArrangement.tssrc/composables/graph/useSelectionMenuOptions.test.tssrc/composables/graph/useSelectionMenuOptions.tssrc/lib/litegraph/src/LGraphCanvas.tssrc/lib/litegraph/src/interfaces.tssrc/lib/litegraph/src/utils/arrange.tssrc/locales/en/main.jsonsrc/locales/en/settings.jsonsrc/platform/settings/constants/coreSettings.tssrc/renderer/core/layout/store/layoutStore.tssrc/renderer/extensions/vueNodes/components/LGraphNode.vuesrc/renderer/extensions/vueNodes/components/NodeWidgets.vuesrc/renderer/extensions/vueNodes/composables/useNodePointerInteractions.tssrc/renderer/extensions/vueNodes/layout/nodeAlignmentSnap.test.tssrc/renderer/extensions/vueNodes/layout/nodeAlignmentSnap.tssrc/renderer/extensions/vueNodes/layout/useNodeDrag.test.tssrc/renderer/extensions/vueNodes/layout/useNodeDrag.tssrc/schemas/apiSchema.ts
| public isDraggingVueNodes = ref(false) | ||
| public vueDragSnapGuides = ref<NodeAlignmentGuide[]>([]) |
There was a problem hiding this comment.
Clear drag guides when the layout store reinitializes.
vueDragSnapGuides is now part of the singleton canvas render state, but initializeFromLiteGraph() still only clears the older layout/render caches. If a workflow reload or mode switch interrupts a drag, _drawVueDragAlignmentGuides() can keep rendering stale guides from the previous graph until another cleanup path happens to run.
🩹 Proposed fix
initializeFromLiteGraph(
nodes: Array<{ id: string; pos: [number, number]; size: [number, number] }>
): void {
+ this.isDraggingVueNodes.value = false
+ this.vueDragSnapGuides.value = []
+
this.ydoc.transact(() => {
this.ynodes.clear()🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/renderer/core/layout/store/layoutStore.ts` around lines 141 - 142, When
reinitializing the layout store in initializeFromLiteGraph(), also reset the
singleton's Vue drag guide state by clearing vueDragSnapGuides and resetting
isDraggingVueNodes so stale guides aren't rendered; update
initializeFromLiteGraph() to set vueDragSnapGuides.value = [] (and
isDraggingVueNodes.value = false if appropriate) so
_drawVueDragAlignmentGuides() has no leftover data to render after a workflow
reload or mode switch.
| function cleanupDragState() { | ||
| layoutStore.isDraggingVueNodes.value = false | ||
| layoutStore.vueDragSnapGuides.value = [] | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Description: Find the test file and check how layoutStore is mocked
# Find and display the layoutStore mock in the test file
rg -n -A 10 'layoutStore' src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.test.tsRepository: Comfy-Org/ComfyUI_frontend
Length of output: 2895
🏁 Script executed:
#!/bin/bash
# Check the actual implementation of cleanupDragState in useNodePointerInteractions.ts
rg -n -B 2 -A 5 'cleanupDragState' src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.tsRepository: Comfy-Org/ComfyUI_frontend
Length of output: 885
🏁 Script executed:
#!/bin/bash
# Check if vueDragSnapGuides is used elsewhere in the file
rg -n 'vueDragSnapGuides' src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.tsRepository: Comfy-Org/ComfyUI_frontend
Length of output: 118
🏁 Script executed:
#!/bin/bash
# Check the complete layoutStore mock setup to confirm vueDragSnapGuides is not included
sed -n '93,107p' src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.test.tsRepository: Comfy-Org/ComfyUI_frontend
Length of output: 487
🏁 Script executed:
#!/bin/bash
# Check if layoutStore is mocked anywhere else with vueDragSnapGuides
rg 'vueDragSnapGuides' src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.test.tsRepository: Comfy-Org/ComfyUI_frontend
Length of output: 52
Add vueDragSnapGuides to the layoutStore mock in the test file.
The cleanupDragState() function at line 105 sets layoutStore.vueDragSnapGuides.value = [], but the test mock at lines 93-107 does not include this property. Existing tests that trigger drag end, cancel, or unmount will fail because they attempt to set a property on undefined. Update the mock to include vueDragSnapGuides: ref([]).
🧰 Tools
🪛 GitHub Actions: CI: Tests Unit
[error] 105-105: Cannot set properties of undefined (setting 'value') in cleanupDragState.
🪛 GitHub Check: test
[failure] 105-105: src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.test.ts > useNodePointerInteractions > on ctrl+click: calls toggleNodeSelectionAfterPointerUp on pointer up (not pointer down)
TypeError: Cannot set properties of undefined (setting 'value')
❯ cleanupDragState src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:105:35
❯ safeDragEnd src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:124:7
❯ Object.onPointerup src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:139:7
❯ src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.test.ts:319:21
[failure] 105-105: src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.test.ts > useNodePointerInteractions > should select node immediately when drag starts
TypeError: Cannot set properties of undefined (setting 'value')
❯ cleanupDragState src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:105:35
❯ safeDragEnd src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:124:7
❯ Object.onPointerup src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:139:7
❯ src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.test.ts:290:21
[failure] 105-105: src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.test.ts > useNodePointerInteractions > should select node immediately when drag starts
TypeError: Cannot set properties of undefined (setting 'value')
❯ cleanupDragState src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:105:35
❯ safeDragEnd src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:124:7
❯ Object.onPointerup src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:139:7
❯ src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.test.ts:290:21
[failure] 105-105: src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.test.ts > useNodePointerInteractions > should select node immediately when drag starts
TypeError: Cannot set properties of undefined (setting 'value')
❯ cleanupDragState src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:105:35
❯ safeDragEnd src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:124:7
❯ Object.onPointerup src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:139:7
❯ src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.test.ts:290:21
[failure] 105-105: src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.test.ts > useNodePointerInteractions > should integrate with layout store dragging state
TypeError: Cannot set properties of undefined (setting 'value')
❯ cleanupDragState src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:105:35
❯ safeDragEnd src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:124:7
❯ Object.onPointercancel src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:159:5
❯ src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.test.ts:255:21
[failure] 105-105: src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.test.ts > useNodePointerInteractions > should integrate with layout store dragging state
TypeError: Cannot set properties of undefined (setting 'value')
❯ cleanupDragState src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:105:35
❯ safeDragEnd src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:124:7
❯ Object.onPointercancel src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:159:5
❯ src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.test.ts:255:21
[failure] 105-105: src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.test.ts > useNodePointerInteractions > should integrate with layout store dragging state
TypeError: Cannot set properties of undefined (setting 'value')
❯ cleanupDragState src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:105:35
❯ safeDragEnd src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:124:7
❯ Object.onPointercancel src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:159:5
❯ src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.test.ts:255:21
[failure] 105-105: src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.test.ts > useNodePointerInteractions > should handle drag termination via cancel and context menu
TypeError: Cannot set properties of undefined (setting 'value')
❯ cleanupDragState src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:105:35
❯ safeDragEnd src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:124:7
❯ Object.onPointercancel src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:159:5
❯ src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.test.ts:206:21
[failure] 105-105: src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.test.ts > useNodePointerInteractions > should handle drag termination via cancel and context menu
TypeError: Cannot set properties of undefined (setting 'value')
❯ cleanupDragState src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:105:35
❯ safeDragEnd src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:124:7
❯ Object.onPointercancel src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:159:5
❯ src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.test.ts:206:21
[failure] 105-105: src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.test.ts > useNodePointerInteractions > should handle drag termination via cancel and context menu
TypeError: Cannot set properties of undefined (setting 'value')
❯ cleanupDragState src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:105:35
❯ safeDragEnd src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:124:7
❯ Object.onPointercancel src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts:159:5
❯ src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.test.ts:206:21
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/renderer/extensions/vueNodes/composables/useNodePointerInteractions.ts`
around lines 103 - 106, The test's layoutStore mock is missing vueDragSnapGuides
which causes cleanupDragState() (in useNodePointerInteractions.cleanupDragState)
to assign to undefined; update the mock object used in the tests to include
vueDragSnapGuides: ref([]) (and import/ref from 'vue' in the test if not already
present) so layoutStore.vueDragSnapGuides.value can be safely assigned during
drag end/cancel/unmount flows.
| const selectedNodes = new Set(toValue(selectedNodeIds)) | ||
| selectedNodes.add(nodeId) | ||
| draggedSelectionBounds = getDraggedSelectionBounds(selectedNodes) | ||
| alignmentCandidateBounds = getAlignmentCandidateBounds(selectedNodes) |
There was a problem hiding this comment.
Keep the opt-in alignment setup behind the opt-in setting.
These bounds are prepared on every drag start, even when
Comfy.Canvas.AlignNodesWhileDragging is off. Since
getAlignmentCandidateBounds() walks the whole node map and the setting
defaults to false, the default drag path now pays the full alignment setup
cost on every drag.
Suggested fix
- draggedSelectionBounds = getDraggedSelectionBounds(selectedNodes)
- alignmentCandidateBounds = getAlignmentCandidateBounds(selectedNodes)
+ if (settingStore.get('Comfy.Canvas.AlignNodesWhileDragging')) {
+ draggedSelectionBounds = getDraggedSelectionBounds(selectedNodes)
+ alignmentCandidateBounds = getAlignmentCandidateBounds(selectedNodes)
+ } else {
+ draggedSelectionBounds = null
+ alignmentCandidateBounds = []
+ }
updateDragSnapGuides([])Also applies to: 304-315
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/renderer/extensions/vueNodes/layout/useNodeDrag.ts` around lines 67 - 70,
Prepare draggedSelectionBounds as before but only compute
alignmentCandidateBounds when the opt-in setting
Comfy.Canvas.AlignNodesWhileDragging is enabled: keep creating selectedNodes
(from toValue(selectedNodeIds) and nodeId) and call
getDraggedSelectionBounds(selectedNodes) unconditionally, but wrap the call to
getAlignmentCandidateBounds(selectedNodes) (and assignment to
alignmentCandidateBounds) in an if-check that reads the
Comfy.Canvas.AlignNodesWhileDragging setting so you avoid walking the node map
when alignment is disabled; apply the same conditional guard around the
analogous calls found later in the file (the other block noted in the review).
| const selectedNodes = new Set(toValue(selectedNodeIds)) | ||
| selectedNodes.add(nodeId) | ||
| draggedSelectionBounds = getDraggedSelectionBounds(selectedNodes) | ||
| alignmentCandidateBounds = getAlignmentCandidateBounds(selectedNodes) | ||
| updateDragSnapGuides([]) | ||
|
|
||
| // capture the starting positions of all other selected nodes | ||
| // Only move other selected items if the dragged node is part of the selection | ||
| const isDraggedNodeInSelection = selectedNodes?.has(nodeId) | ||
| const isDraggedNodeInSelection = selectedNodes.has(nodeId) |
There was a problem hiding this comment.
Preserve the original selection membership before adding the dragged node.
selectedNodes.add(nodeId) makes the later membership check always true, so the
“dragging an unrelated node” case never survives. That can pull the previously
selected nodes/groups into the drag path and also removes them from the
alignment-candidate set.
Suggested fix
- const selectedNodes = new Set(toValue(selectedNodeIds))
- selectedNodes.add(nodeId)
- draggedSelectionBounds = getDraggedSelectionBounds(selectedNodes)
- alignmentCandidateBounds = getAlignmentCandidateBounds(selectedNodes)
+ const selectedNodes = new Set(toValue(selectedNodeIds))
+ const isDraggedNodeInSelection = selectedNodes.has(nodeId)
+ const draggedNodeIds = isDraggedNodeInSelection
+ ? selectedNodes
+ : new Set<NodeId>([nodeId])
+
+ draggedSelectionBounds = getDraggedSelectionBounds(draggedNodeIds)
+ alignmentCandidateBounds = getAlignmentCandidateBounds(draggedNodeIds)
updateDragSnapGuides([])
- const isDraggedNodeInSelection = selectedNodes.has(nodeId)
-
- if (isDraggedNodeInSelection && selectedNodes.size > 1) {
+ if (isDraggedNodeInSelection && draggedNodeIds.size > 1) {
otherSelectedNodesStartPositions = new Map()
- for (const id of selectedNodes) {
+ for (const id of draggedNodeIds) {
// Skip the current node being dragged
if (id === nodeId) continueAlso applies to: 77-83, 95-100
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/renderer/extensions/vueNodes/layout/useNodeDrag.ts` around lines 67 - 75,
The code currently mutates selectedNodes by calling selectedNodes.add(nodeId)
before checking membership, so isDraggedNodeInSelection is always true; fix by
determining whether the dragged node is in the original selection first (compute
isDraggedNodeInSelection = toValue(selectedNodeIds).has(nodeId) or check
membership against a Set created from toValue(selectedNodeIds)), then add nodeId
to selectedNodes and call getDraggedSelectionBounds,
getAlignmentCandidateBounds, updateDragSnapGuides; apply the same change to the
other similar blocks referenced around the isDraggedNodeInSelection usage (the
blocks around lines 77-83 and 95-100) to preserve original selection membership
before mutation.
|
Replaced by #9894 |
Summary
Add Nodes 2.0 drag alignment snapping and expose richer multi-node arrangement actions from the right-click menu.
Changes
Comfy.Canvas.AlignNodesWhileDraggingsetting, snap Vue-node drags to nearby rendered node edges and centers with visible guides, add horizontal/vertical center alignment actions, and gate arrangement actions to the multi-node right-click menu instead of the selection-toolbox More Options menu.Review Focus
Verification
pnpm test:unit -- src/renderer/extensions/vueNodes/layout/nodeAlignmentSnap.test.ts src/renderer/extensions/vueNodes/layout/useNodeDrag.test.ts src/composables/graph/useMoreOptionsMenu.test.ts src/composables/graph/useSelectionMenuOptions.test.tspnpm typecheckpnpm typecheck:browserpnpm format:checkpnpm linthttp://localhost:8188was unavailable (ECONNREFUSEDon/api/users).Screenshots (if applicable)
┆Issue is synchronized with this Notion page by Unito