fix: handle undefined edge list in insertEdge to prevent runtime error

Fixes a runtime error in cose-bilkent layout caused by insertEdge calling .filter() on an undefined edge list. Now defaults to an empty array to prevent the crash.

on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
This commit is contained in:
darshanr0107
2025-07-23 17:18:48 +05:30
parent cd6f8e5a24
commit 425fb7ee33
2 changed files with 14 additions and 4 deletions

View File

@@ -115,6 +115,18 @@ export const render = async (
}
});
layoutResult.edges.forEach((positionedEdge) => {
const edge = data4Layout.edges.find((e) => e.id === positionedEdge.id);
if (edge) {
// Update the edge data with positioned coordinates
edge.points = [
{ x: positionedEdge.startX, y: positionedEdge.startY },
{ x: positionedEdge.midX, y: positionedEdge.midY },
{ x: positionedEdge.endX, y: positionedEdge.endY },
];
}
});
// Step 4: Insert and position edges
log.debug('Inserting and positioning edges');
@@ -134,10 +146,7 @@ export const render = async (
if (positionedEdge) {
log.debug('APA01 positionedEdge', positionedEdge);
// Create edge path with positioned coordinates
const edgeWithPath = {
...edge,
points: positionedEdge.points,
};
const edgeWithPath = { ...edge };
// Insert the edge path
const paths = insertEdge(

View File

@@ -128,6 +128,7 @@ export interface Edge {
thickness?: 'normal' | 'thick' | 'invisible' | 'dotted';
look?: string;
isUserDefinedId?: boolean;
points?: Point[];
}
export interface RectOptions {