From e2f109807c4ca29ae729a4e52b014fcb1ab4b652 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Sun, 19 May 2024 19:37:26 +1000 Subject: [PATCH] fix(ui): delete edges when their source or target no longer exists --- .../web/src/features/nodes/store/nodesSlice.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/invokeai/frontend/web/src/features/nodes/store/nodesSlice.ts b/invokeai/frontend/web/src/features/nodes/store/nodesSlice.ts index 9cc641769c..c63734c871 100644 --- a/invokeai/frontend/web/src/features/nodes/store/nodesSlice.ts +++ b/invokeai/frontend/web/src/features/nodes/store/nodesSlice.ts @@ -93,6 +93,16 @@ export const nodesSlice = createSlice({ reducers: { nodesChanged: (state, action: PayloadAction) => { state.nodes = applyNodeChanges(action.payload, state.nodes); + // Remove edges that are no longer valid, due to a removed or otherwise changed node + const edgeChanges: EdgeChange[] = []; + state.edges.forEach((e) => { + const sourceExists = state.nodes.some((n) => n.id === e.source); + const targetExists = state.nodes.some((n) => n.id === e.target); + if (!(sourceExists && targetExists)) { + edgeChanges.push({ type: 'remove', id: e.id }); + } + }); + state.edges = applyEdgeChanges(edgeChanges, state.edges); }, edgesChanged: (state, action: PayloadAction) => { const changes = deepClone(action.payload);