Skip to content

Commit 2a5e0d2

Browse files
benceruleanluchristian-byrneclaudegithub-actions
authored
Decouple link and slot hit-testing out of Litegraph (#5134)
* [feat] TransformPane - Viewport synchronization layer for Vue nodes (#4304) Co-authored-by: Claude <[email protected]> Co-authored-by: Benjamin Lu <[email protected]> Co-authored-by: github-actions <[email protected]> * Update locales [skip ci] * Update locales [skip ci] * Add vue node feature flag (#4927) * feat: Implement CRDT-based layout system for Vue nodes (#4959) * feat: Implement CRDT-based layout system for Vue nodes Major refactor to solve snap-back issues and create single source of truth for node positions: - Add Yjs-based CRDT layout store for conflict-free position management - Implement layout mutations service with clean API - Create Vue composables for layout access and node dragging - Add one-way sync from layout store to LiteGraph - Disable LiteGraph dragging when Vue nodes mode is enabled - Add z-index management with bring-to-front on node interaction - Add comprehensive TypeScript types for layout system - Include unit tests for layout store operations - Update documentation to reflect CRDT architecture This provides a solid foundation for both single-user performance and future real-time collaboration features. Co-Authored-By: Claude <[email protected]> * style: Apply linter fixes to layout system * fix: Remove unnecessary README files and revert services README - Remove unnecessary types/README.md file - Revert unrelated changes to services/README.md - Keep only relevant documentation for the layout system implementation These were issues identified during PR review that needed to be addressed. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * refactor: Clean up layout store and implement proper CRDT operations - Created dedicated layoutOperations.ts with production-grade CRDT interfaces - Integrated existing QuadTree spatial index instead of simple cache - Split composables into separate files (useLayout, useNodeLayout, useLayoutSync) - Cleaned up operation handlers using specific types instead of Extract - Added proper operation interfaces with type guards and extensibility - Updated all type references to use new operation structure The layout store now properly uses the existing QuadTree infrastructure for efficient spatial queries and follows CRDT best practices with well-defined operation interfaces. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * refactor: Extract services and split composables for better organization - Created SpatialIndexManager to handle QuadTree operations separately - Added LayoutAdapter interface for CRDT abstraction (Yjs, mock implementations) - Split GraphNodeManager into focused composables: - useNodeWidgets: Widget state and callback management - useNodeChangeDetection: RAF-based geometry change detection - useNodeState: Node visibility and reactive state management - Extracted constants for magic numbers and configuration values - Updated layout store to use SpatialIndexManager and constants This improves code organization, testability, and makes it easier to swap CRDT implementations or mock services for testing. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * Add node slots to layout tree * Revert "Add node slots to layout tree" This reverts commit 460493a. * Remove slots from layoutTypes * Totally not scuffed renderer and adapter * Revert "Totally not scuffed renderer and adapter" This reverts commit 2b9d83e. * Revert "Remove slots from layoutTypes" This reverts commit 18f78ff. * Reapply "Add node slots to layout tree" This reverts commit 236fecb. * Revert "Add node slots to layout tree" This reverts commit 460493a. * docs: Replace architecture docs with comprehensive ADR - Add ADR-0002 for CRDT-based layout system decision - Follow established ADR template with persuasive reasoning - Include performance benefits, collaboration readiness, and architectural advantages - Update ADR index --------- Co-authored-by: Claude <[email protected]> Co-authored-by: Benjamin Lu <[email protected]> * [chore] Extract link rendering out of LGraphCanvas (#4994) * feat: Implement CRDT-based layout system for Vue nodes Major refactor to solve snap-back issues and create single source of truth for node positions: - Add Yjs-based CRDT layout store for conflict-free position management - Implement layout mutations service with clean API - Create Vue composables for layout access and node dragging - Add one-way sync from layout store to LiteGraph - Disable LiteGraph dragging when Vue nodes mode is enabled - Add z-index management with bring-to-front on node interaction - Add comprehensive TypeScript types for layout system - Include unit tests for layout store operations - Update documentation to reflect CRDT architecture This provides a solid foundation for both single-user performance and future real-time collaboration features. Co-Authored-By: Claude <[email protected]> * style: Apply linter fixes to layout system * fix: Remove unnecessary README files and revert services README - Remove unnecessary types/README.md file - Revert unrelated changes to services/README.md - Keep only relevant documentation for the layout system implementation These were issues identified during PR review that needed to be addressed. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * refactor: Clean up layout store and implement proper CRDT operations - Created dedicated layoutOperations.ts with production-grade CRDT interfaces - Integrated existing QuadTree spatial index instead of simple cache - Split composables into separate files (useLayout, useNodeLayout, useLayoutSync) - Cleaned up operation handlers using specific types instead of Extract - Added proper operation interfaces with type guards and extensibility - Updated all type references to use new operation structure The layout store now properly uses the existing QuadTree infrastructure for efficient spatial queries and follows CRDT best practices with well-defined operation interfaces. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * refactor: Extract services and split composables for better organization - Created SpatialIndexManager to handle QuadTree operations separately - Added LayoutAdapter interface for CRDT abstraction (Yjs, mock implementations) - Split GraphNodeManager into focused composables: - useNodeWidgets: Widget state and callback management - useNodeChangeDetection: RAF-based geometry change detection - useNodeState: Node visibility and reactive state management - Extracted constants for magic numbers and configuration values - Updated layout store to use SpatialIndexManager and constants This improves code organization, testability, and makes it easier to swap CRDT implementations or mock services for testing. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * Add node slots to layout tree * Revert "Add node slots to layout tree" This reverts commit 460493a. * Remove slots from layoutTypes * Totally not scuffed renderer and adapter * Revert "Totally not scuffed renderer and adapter" This reverts commit 2b9d83e. * Revert "Remove slots from layoutTypes" This reverts commit 18f78ff. * Reapply "Add node slots to layout tree" This reverts commit 236fecb. * Revert "Add node slots to layout tree" This reverts commit 460493a. * docs: Replace architecture docs with comprehensive ADR - Add ADR-0002 for CRDT-based layout system decision - Follow established ADR template with persuasive reasoning - Include performance benefits, collaboration readiness, and architectural advantages - Update ADR index * Add node slots to layout tree * Revert "Add node slots to layout tree" This reverts commit 460493a. * Remove slots from layoutTypes * Totally not scuffed renderer and adapter * Remove unused methods in LGLA * Extract slot position calculations to shared utility - Create slotCalculations.ts utility for centralized slot position logic - Update LGraphNode to delegate to helper while maintaining compatibility - Modify LitegraphLinkAdapter to use layout tree positions when available - Enable link rendering to use layout system coordinates instead of litegraph positions This allows the layout tree to control link rendering positions, enabling proper synchronization between Vue components and canvas rendering. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * [fix] Restore original link rendering behavior after refactor This commit fixes several rendering discrepancies introduced during the link rendering refactor to ensure exact parity with the original litegraph implementation: Path Shape Fixes: - STRAIGHT_LINK: Now correctly applies l=10 offset to create innerA/innerB points and uses midX=(innerA.x+innerB.x)*0.5 for elbow placement, matching the original 6-segment path - LINEAR_LINK: Restored 4-point path with l=15 directional offsets (start → innerA → innerB → end) Arrow Rendering: - computeConnectionPoint: Now always uses bezier math with 0.25 factor spline offsets regardless of render mode, ensuring arrow positions match original - Arrow positions: Fixed to render at 0.25 and 0.75 positions along the path - Arrow gating: Moved scale>=0.6 and highQuality checks to adapter layer to maintain PathRenderer purity - Arrow shape: Restored original triangle dimensions (-5,-3) to (0,+7) to (+5,-3) Center Marker: - Fixed 'None' option: Center marker now correctly hidden when LinkMarkerShape.None is selected - Center point calculation: Updated for all render modes to match original positions - STRAIGHT_LINK center: Uses midX and average of innerA/innerB y-coordinates - LINEAR_LINK center: Uses midpoint between innerA and innerB control points These fixes ensure backward compatibility while maintaining the clean separation between the pure PathRenderer and litegraph-specific LitegraphLinkAdapter. Fixes #Issue-Number --------- Co-authored-by: bymyself <[email protected]> Co-authored-by: Claude <[email protected]> * feat: Add slot registration and spatial indexing for hit detection - Implement slot registration for all nodes (Vue and LiteGraph) - Add spatial indexes for slots and reroutes to improve hit detection performance - Register slots when nodes are drawn via new registerSlots() method - Update LayoutStore to use spatial indexing for O(log n) queries instead of O(n) Resolves #5125 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * Revert "feat: Add slot registration and spatial indexing for hit detection" This reverts commit 70fbfd0. * feat: Add slot registration and spatial indexing for hit detection - Implement slot registration for all nodes (Vue and LiteGraph) - Add spatial indexes for slots and reroutes to improve hit detection performance - Register slots when nodes are drawn via new registerSlots() method - Update LayoutStore to use spatial indexing for O(log n) queries instead of O(n) Resolves #5125 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * relocate slot update to layoutstore * Revert "relocate slot update to layoutstore" This reverts commit 0b17ef1. * add useSlotLayoutSync * feat: Extend Layout Store with CRDT support for links and reroutes Move links and reroutes to be first-class CRDT entities in the Layout Store, eliminating per-frame registration during rendering. This provides a ~100x reduction in spatial index operations by using event-driven updates instead of polling. Key changes: - Add CRDT maps for links and reroutes with automatic observers - Add mutation operations for link/reroute lifecycle management - Update LiteGraph to use mutations instead of direct store calls - Remove per-frame updateLinkLayout and updateRerouteLayout calls 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * Scuffed diff, change to dirty later * Fix reroute move desync * Terrible reroute fixes * Use LinkId for LinkLayout * refactor: Remove unused duplicate layout type files Deleted src/types/layoutTypes.ts and src/types/layoutOperations.ts which were duplicates of src/renderer/core/layout/types.ts. These files had zero imports and were creating confusion in the codebase. The active types are in src/renderer/core/layout/types.ts which is properly integrated with the current architecture. 🤖 Generated with Claude Code Co-Authored-By: Claude <[email protected]> * refactor: Extract layout source strings into LayoutSource enum Replace hardcoded 'canvas' | 'vue' | 'external' string literals with a proper TypeScript enum for better type safety and maintainability. This change provides a single source of truth for layout source types and makes future modifications easier. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * refactor: Unify CRDT layout operations under type-safe entity bases Replace node-centric BaseOperation with a clean hierarchy: - Add OperationMeta base containing common fields (timestamp, actor, source, type) - Introduce entity-specific bases (NodeOpBase, LinkOpBase, RerouteOpBase) - Each operation now extends its appropriate entity base with proper typing - Add entity discriminator field for runtime type narrowing Benefits: - Eliminates duplicate meta fields across link/reroute operations - Provides type-safe discriminated unions for each entity type - Enables clean extension path for future operation types - Zero breaking changes - type-only refactor with no runtime impact Also adds helper functions: - getAffectedNodeIds() to extract node IDs affected by any operation - Entity-specific helper checks for operation classification 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * Fix initial link seeding * fix: Fix reroute hit detection and type consistency issues - Use instanceof Reroute type guard instead of structural 'linkIds' check - Remove unnecessary Number() conversions for reroute IDs (already numeric) - Fix parentId truthiness bug (0 is valid parent ID) - Pass numeric IDs directly in GraphCanvas seeding - Add missing link/reroute methods to LayoutMutations interface - Make hit test tolerance scale-aware using ctx.lineWidth and DPI 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * Add debug logs * Add missing reroute path * cleanup * feat: Implement event-driven link layout sync Remove layout store writes from render loop and update link geometry only on actual changes (node move/resize, link/reroute operations, collapse toggles). Key improvements: - No layout writes during canvas render (decoupled from draw cycle) - Link layouts update only on causal events via useLinkLayoutSync - Hit testing remains precise using stored Path2D objects - Optimized adapter: calculations only when enableLayoutStoreWrites=true - Store-level deduplication prevents spatial index churn Performance impact: - Render path: Zero layout work, no equality checks, no store writes - Event path: Direct writes with cheap store-level dedup - Significant CPU savings per frame on complex graphs 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * feat: Implement DOM-based slot registration with unified position system - Add centralized getSlotPosition() function in SlotCalculations - Create SlotIdentifier utilities for consistent slot key generation - Implement DOM-based slot registration composable with performance optimizations: - Cache slot offsets to avoid DOM reads during drag operations - Batch measurements via requestAnimationFrame - Skip redundant updates when bounds unchanged - Update Vue slot components to register DOM positions - Fix widget-to-input index mapping in NodeWidgets - Prevent double registration when Vue nodes enabled This improves slot hit-detection accuracy by using actual DOM positions while maintaining performance through intelligent caching and batching. 🤖 Generated with Claude Code Co-Authored-By: Claude <[email protected]> * Remove unused files * Remove duplicated markdown file * Remove duplicated files and address knip concerns * Remove outdated test * warning comment * Update test snapshots --------- Co-authored-by: Christian Byrne <[email protected]> Co-authored-by: Claude <[email protected]> Co-authored-by: github-actions <[email protected]>
1 parent 0830959 commit 2a5e0d2

File tree

89 files changed

+2465
-5732
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+2465
-5732
lines changed

src/components/graph/GraphCanvas.vue

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ import type { LGraphCanvas, LGraphNode } from '@/lib/litegraph/src/litegraph'
142142
import { layoutStore } from '@/renderer/core/layout/store/LayoutStore'
143143
import { useLayout } from '@/renderer/core/layout/sync/useLayout'
144144
import { useLayoutSync } from '@/renderer/core/layout/sync/useLayoutSync'
145+
import { useLinkLayoutSync } from '@/renderer/core/layout/sync/useLinkLayoutSync'
146+
import { useSlotLayoutSync } from '@/renderer/core/layout/sync/useSlotLayoutSync'
147+
import { LayoutSource } from '@/renderer/core/layout/types'
145148
import VueGraphNode from '@/renderer/extensions/vueNodes/components/LGraphNode.vue'
146149
import { UnauthorizedError, api } from '@/scripts/api'
147150
import { app as comfyApp } from '@/scripts/app'
@@ -283,6 +286,10 @@ watch(canvasRef, () => {
283286
// Vue node lifecycle management - initialize after graph is ready
284287
let nodeManager: ReturnType<typeof useGraphNodeManager> | null = null
285288
let cleanupNodeManager: (() => void) | null = null
289+
290+
// Slot layout sync management
291+
let slotSync: ReturnType<typeof useSlotLayoutSync> | null = null
292+
let linkSync: ReturnType<typeof useLinkLayoutSync> | null = null
286293
const vueNodeData = ref<ReadonlyMap<string, VueNodeData>>(new Map())
287294
const nodeState = ref<ReadonlyMap<string, NodeState>>(new Map())
288295
const nodePositions = ref<ReadonlyMap<string, { x: number; y: number }>>(
@@ -324,15 +331,46 @@ const initializeNodeManager = () => {
324331
}))
325332
layoutStore.initializeFromLiteGraph(nodes)
326333
334+
// Seed reroutes into the Layout Store so hit-testing uses the new path
335+
for (const reroute of comfyApp.graph.reroutes.values()) {
336+
const [x, y] = reroute.pos
337+
const parent = reroute.parentId ?? undefined
338+
const linkIds = Array.from(reroute.linkIds)
339+
layoutMutations.createReroute(reroute.id, { x, y }, parent, linkIds)
340+
}
341+
342+
// Seed existing links into the Layout Store (topology only)
343+
for (const link of comfyApp.graph._links.values()) {
344+
layoutMutations.createLink(
345+
link.id,
346+
link.origin_id,
347+
link.origin_slot,
348+
link.target_id,
349+
link.target_slot
350+
)
351+
}
352+
327353
// Initialize layout sync (one-way: Layout Store → LiteGraph)
328354
const { startSync } = useLayoutSync()
329355
startSync(canvasStore.canvas)
330356
357+
// Initialize slot layout sync for hit detection
358+
slotSync = useSlotLayoutSync()
359+
if (canvasStore.canvas) {
360+
slotSync.start(canvasStore.canvas as LGraphCanvas)
361+
}
362+
363+
// Initialize link layout sync for event-driven updates
364+
linkSync = useLinkLayoutSync()
365+
if (canvasStore.canvas) {
366+
linkSync.start(canvasStore.canvas as LGraphCanvas)
367+
}
368+
331369
// Force computed properties to re-evaluate
332370
nodeDataTrigger.value++
333371
}
334372
335-
const disposeNodeManager = () => {
373+
const disposeNodeManagerAndSyncs = () => {
336374
if (!nodeManager) return
337375
try {
338376
cleanupNodeManager?.()
@@ -341,6 +379,19 @@ const disposeNodeManager = () => {
341379
}
342380
nodeManager = null
343381
cleanupNodeManager = null
382+
383+
// Clean up slot layout sync
384+
if (slotSync) {
385+
slotSync.stop()
386+
slotSync = null
387+
}
388+
389+
// Clean up link layout sync
390+
if (linkSync) {
391+
linkSync.stop()
392+
linkSync = null
393+
}
394+
344395
// Reset reactive maps to inert defaults
345396
vueNodeData.value = new Map()
346397
nodeState.value = new Map()
@@ -360,7 +411,7 @@ watch(
360411
if (enabled) {
361412
initializeNodeManager()
362413
} else {
363-
disposeNodeManager()
414+
disposeNodeManagerAndSyncs()
364415
}
365416
},
366417
{ immediate: true }
@@ -509,7 +560,7 @@ const handleNodeSelect = (event: PointerEvent, nodeData: VueNodeData) => {
509560
// Bring node to front when clicked (similar to LiteGraph behavior)
510561
// Skip if node is pinned
511562
if (!node.flags?.pinned) {
512-
layoutMutations.setSource('vue')
563+
layoutMutations.setSource(LayoutSource.Vue)
513564
layoutMutations.bringNodeToFront(nodeData.id)
514565
}
515566
node.selected = true
@@ -827,5 +878,17 @@ onUnmounted(() => {
827878
nodeManager.cleanup()
828879
nodeManager = null
829880
}
881+
882+
// Clean up slot layout sync
883+
if (slotSync) {
884+
slotSync.stop()
885+
slotSync = null
886+
}
887+
888+
// Clean up link layout sync
889+
if (linkSync) {
890+
linkSync.stop()
891+
linkSync = null
892+
}
830893
})
831894
</script>

src/components/graph/debug/QuadTreeDebugSection.vue

Lines changed: 0 additions & 112 deletions
This file was deleted.

src/components/graph/debug/QuadTreeVisualization.vue

Lines changed: 0 additions & 112 deletions
This file was deleted.

src/components/graph/vueWidgets/WidgetButton.vue

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)