diff --git a/plugins/lime-plugin-mesh-wide/src/lib/links/getLinksCoordinates.ts b/plugins/lime-plugin-mesh-wide/src/lib/links/getLinksCoordinates.ts index 26e3de9f..19ad7d69 100644 --- a/plugins/lime-plugin-mesh-wide/src/lib/links/getLinksCoordinates.ts +++ b/plugins/lime-plugin-mesh-wide/src/lib/links/getLinksCoordinates.ts @@ -34,11 +34,15 @@ export const mergeLinksAndCoordinates = ( // Find destination link info from shared state let dest: IBaseLink; for (const destNodeKey in links) { - const link = Object.entries(links[destNodeKey].links).find( - ([key]) => key === linkKey && destNodeKey !== actualNodeName - ); - if (link) { - dest = { [destNodeKey]: link[1] }; + // Prevent empty objects crashing from shared state + if (links[destNodeKey] && !isEmpty(links[destNodeKey]?.links)) { + const link = Object.entries(links[destNodeKey].links).find( + ([key]) => + key === linkKey && destNodeKey !== actualNodeName + ); + if (link) { + dest = { [destNodeKey]: link[1] }; + } } } diff --git a/src/utils/utils.tsx b/src/utils/utils.tsx index 68b889a4..4e5ecab2 100644 --- a/src/utils/utils.tsx +++ b/src/utils/utils.tsx @@ -1,3 +1,8 @@ -export function isEmpty(obj: object): boolean { +export function isEmpty(obj: object | null | undefined): boolean { + // Check if the input is null, undefined, or not an object + if (obj == null || typeof obj !== "object") { + return true; + } + // Return true if the object has no own properties return Object.keys(obj).length === 0; }