diff --git a/.changeset/strong-suns-grow.md b/.changeset/strong-suns-grow.md new file mode 100644 index 00000000..67d773bc --- /dev/null +++ b/.changeset/strong-suns-grow.md @@ -0,0 +1,5 @@ +--- +'@xyflow/react': patch +--- + +Handle undefined node in mini map diff --git a/packages/react/src/additional-components/MiniMap/MiniMapNodes.tsx b/packages/react/src/additional-components/MiniMap/MiniMapNodes.tsx index e96dd9f6..0734df3f 100644 --- a/packages/react/src/additional-components/MiniMap/MiniMapNodes.tsx +++ b/packages/react/src/additional-components/MiniMap/MiniMapNodes.tsx @@ -84,13 +84,18 @@ function NodeComponentWrapperInner({ shapeRendering: string; }) { const { node, x, y, width, height } = useStore((s) => { - const { internals } = s.nodeLookup.get(id)!; - const node = internals.userNode as NodeType; - const { x, y } = internals.positionAbsolute; - const { width, height } = getNodeDimensions(node); + const node = s.nodeLookup.get(id); + + if (!node) { + return { node: undefined, x: 0, y: 0, width: 0, height: 0 }; + } + + const userNode = node.internals.userNode as NodeType; + const { x, y } = node.internals.positionAbsolute; + const { width, height } = getNodeDimensions(userNode); return { - node, + node: userNode, x, y, width,