diff --git a/.changeset/twelve-olives-fly.md b/.changeset/twelve-olives-fly.md new file mode 100644 index 00000000..75bb2f92 --- /dev/null +++ b/.changeset/twelve-olives-fly.md @@ -0,0 +1,5 @@ +--- +"@vue-flow/core": patch +--- + +Use correct handlesuffix for connection lookup in `getHandleConnections` action. diff --git a/examples/vite/src/Basic/Basic.vue b/examples/vite/src/Basic/Basic.vue index c5be8653..f23c150c 100644 --- a/examples/vite/src/Basic/Basic.vue +++ b/examples/vite/src/Basic/Basic.vue @@ -6,11 +6,14 @@ import { Background } from '@vue-flow/background' import { Controls } from '@vue-flow/controls' import { MiniMap } from '@vue-flow/minimap' -const elements = ref([ +const nodes = ref([ { id: '1', type: 'input', label: 'Node 1', position: { x: 250, y: 5 }, class: 'light' }, { id: '2', label: 'Node 2', position: { x: 100, y: 100 }, class: 'light' }, { id: '3', label: 'Node 3', position: { x: 400, y: 100 }, class: 'light' }, { id: '4', label: 'Node 4', position: { x: 400, y: 200 }, class: 'light' }, +]) + +const edges = ref([ { id: 'e1-2', source: '1', target: '2', animated: true }, { id: 'e1-3', source: '1', target: '3' }, ]) @@ -23,7 +26,7 @@ const { onConnect, addEdges, setViewport, toObject } = useVueFlow({ onConnect(addEdges) function updatePos() { - return elements.value.forEach((el) => { + return nodes.value.forEach((el) => { if (isNode(el)) { el.position = { x: Math.random() * 400, @@ -40,16 +43,23 @@ function resetViewport() { return setViewport({ x: 0, y: 0, zoom: 1 }) } function toggleclass() { - return elements.value.forEach((el) => (el.class = el.class === 'light' ? 'dark' : 'light')) + return nodes.value.forEach((el) => (el.class = el.class === 'light' ? 'dark' : 'light')) } + + diff --git a/packages/core/src/store/actions.ts b/packages/core/src/store/actions.ts index ab8616d1..83c5520e 100644 --- a/packages/core/src/store/actions.ts +++ b/packages/core/src/store/actions.ts @@ -73,7 +73,8 @@ export function useActions(state: State, nodeLookup: ComputedRef, ed } const getHandleConnections: Actions['getHandleConnections'] = ({ id, type, nodeId }) => { - return Array.from(state.connectionLookup.get(`${nodeId}-${type}-${id ?? null}`)?.values() ?? []) + const handleSuffix = id ? `-${type}-${id}` : `-${type}` + return Array.from(state.connectionLookup.get(`${nodeId}${handleSuffix}`)?.values() ?? []) } const findNode: Actions['findNode'] = (id) => {