Implement proper invalidation on switch (#5383)

This commit is contained in:
Benjamin Lu
2025-09-06 01:49:01 -07:00
committed by snomiao
parent e86996472b
commit 997f14ee5c
4 changed files with 55 additions and 21 deletions

View File

@@ -410,6 +410,15 @@ class LayoutStoreImpl implements LayoutStore {
}
}
/**
* Clear all slot layouts and their spatial index (O(1) operations)
* Used when switching rendering modes (Vue ↔ LiteGraph)
*/
clearAllSlotLayouts(): void {
this.slotLayouts.clear()
this.slotSpatialIndex.clear()
}
/**
* Update reroute layout data
*/

View File

@@ -16,7 +16,7 @@ import { layoutStore } from '@/renderer/core/layout/store/layoutStore'
* Compute and register slot layouts for a node
* @param node LiteGraph node to process
*/
function computeAndRegisterSlots(node: LGraphNode): void {
export function computeAndRegisterSlots(node: LGraphNode): void {
const nodeId = String(node.id)
const nodeLayout = layoutStore.getNodeLayoutRef(nodeId).value
@@ -57,17 +57,18 @@ export function useSlotLayoutSync() {
let restoreHandlers: (() => void) | null = null
/**
* Start slot layout sync with full event-driven functionality
* Attempt to start slot layout sync with full event-driven functionality
* @param canvas LiteGraph canvas instance
* @returns true if sync was actually started, false if early-returned
*/
function start(canvas: LGraphCanvas): void {
function attemptStart(canvas: LGraphCanvas): boolean {
// When Vue nodes are enabled, slot DOM registers exact positions.
// Skip calculated registration to avoid conflicts.
if (LiteGraph.vueNodesMode) {
return
return false
}
const graph = canvas?.graph
if (!graph) return
if (!graph) return false
// Initial registration for all nodes in the current graph
for (const node of graph.nodes) {
@@ -135,6 +136,8 @@ export function useSlotLayoutSync() {
graph.onTrigger = origTrigger || undefined
graph.onAfterChange = origAfterChange || undefined
}
return true
}
/**
@@ -157,7 +160,7 @@ export function useSlotLayoutSync() {
})
return {
start,
attemptStart,
stop
}
}

View File

@@ -297,6 +297,7 @@ export interface LayoutStore {
deleteSlotLayout(key: string): void
deleteNodeSlotLayouts(nodeId: NodeId): void
deleteRerouteLayout(rerouteId: RerouteId): void
clearAllSlotLayouts(): void
// Get layout data
getLinkLayout(linkId: LinkId): LinkLayout | null