diff --git a/apps/opik-frontend/src/components/shared/TraceDetailsPanel/TraceTreeViewer/TraceTreeViewer.tsx b/apps/opik-frontend/src/components/shared/TraceDetailsPanel/TraceTreeViewer/TraceTreeViewer.tsx index 75d60abff..67d9054ac 100644 --- a/apps/opik-frontend/src/components/shared/TraceDetailsPanel/TraceTreeViewer/TraceTreeViewer.tsx +++ b/apps/opik-frontend/src/components/shared/TraceDetailsPanel/TraceTreeViewer/TraceTreeViewer.tsx @@ -173,7 +173,7 @@ const TraceTreeViewer: React.FunctionComponent = ({ ); const maxWidth = useMemo(() => { - const map: Record = {}; + const map: Record = {}; const list: ItemWidthObject[] = traceSpans.map((s) => ({ id: s.id, name: s.name || "", @@ -193,7 +193,13 @@ const TraceTreeViewer: React.FunctionComponent = ({ list.forEach((item) => { if (item.parentId) { - list[map[item.parentId]].children.push(item); + const listIndex = map[item.parentId]; + + if (listIndex !== undefined) { + list[listIndex].children.push(item); + } else { + console.warn(`Parent ${item.parentId} not found for ${item.id}`); + } } else { rootElement.children.push(item); }