bcakmakoglu / vue-flow

A highly customizable Flowchart component for Vue 3. Features seamless zoom & pan šŸ”Ž, additional components like a Minimap šŸ—ŗ and utilities to interact with state and graph.
https://vueflow.dev/
MIT License
4.02k stars 258 forks source link

šŸ› [BUG]: onConnect sourceHandle/targetHandle is null #1498

Closed delphi-sucks closed 4 months ago

delphi-sucks commented 4 months ago

Is there an existing issue for this?

Current Behavior

The Event onConnect gives the following object, if two nodes are connected:

{
  "source": "1",
  "sourceHandle": null,
  "target": "2",
  "targetHandle": null,
}

Expected Behavior

The Event onConnect should also contain the handles

{
  "source": "1",
  "sourceHandle": "1__handle-right",
  "target": "2",
  "targetHandle": "2__handle-left",
}

Steps To Reproduce

Use the following example (or the curent one in the website) and connect the nodes.

console.log will return the invalid object.

<script setup>
import { ref } from 'vue'
import { VueFlow, useVueFlow } from '@vue-flow/core'

const nodes = ref([
  {
    id: '1',
    position: { x: 0, y: 0},
  },
  {
    id: '2',
    position: { x: 250, y: 0 },
  },
])

</script>

<template>
  <VueFlow
    :nodes="nodes"
    @connect="(connection) => console.log(connection)"
  />
</template>

Relevant log output

No response

Anything else?

It previously worked on version 1.23.0.

bcakmakoglu commented 4 months ago

This has been changed. Handles will not receive default ids anymore since that lead to it's own bugs and issues. If you want handle ids to not be null, assign an explicit id to the handle.

delphi-sucks commented 4 months ago

Alright ^^b

For Documentation sake for anyone working with old data, that would need to be migrated otherwise:

<template>
    <slot />
    <Handle
        :id="`${props.id}__handle-top`"
        :position="Position.Top"
    />
    <Handle
        :id="`${props.id}__handle-left`"
        :position="Position.Left"
    />
    <Handle
        :id="`${props.id}__handle-right`"
        :position="Position.Right"
    />
    <Handle
        :id="`${props.id}__handle-bottom`"
        :position="Position.Bottom"
    />
</template>

<script setup lang="ts">
import { Handle, NodeProps, Position } from "@vue-flow/core";

const props = defineProps<NodeProps>();
</script>