Skip to content

Commit

Permalink
馃悰 (editor) Improve edge resiliency connected to non-existant blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Mar 10, 2024
1 parent 0dc276c commit 22fe502
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions apps/builder/src/features/graph/components/edges/Edge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,18 @@ export const Edge = ({ edge, fromGroupId }: Props) => {
return sourceEndpointYOffsets.get(endpointId)?.y
}, [edge.from, sourceEndpointYOffsets])

const targetTop = useMemo(
() =>
edge?.to.blockId
? targetEndpointYOffsets.get(edge?.to.blockId)?.y
: undefined,
[edge?.to.blockId, targetEndpointYOffsets]
)
const targetTop = useMemo(() => {
if (edge.to.blockId) {
const targetOffset = targetEndpointYOffsets.get(edge.to.blockId)
if (!targetOffset) {
// Something went wrong, the edge is connected to a block that doesn't exist anymore.
deleteEdge(edge.id)
return
}
return targetOffset.y
}
return
}, [deleteEdge, edge.id, edge.to.blockId, targetEndpointYOffsets])

const path = useMemo(() => {
if (!sourceElementCoordinates || !toGroupCoordinates || !sourceTop)
Expand Down

2 comments on commit 22fe502

@Trystan4861
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@baptisteArno
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.