Skip to content

Commit

Permalink
Hotfix mesh map (#448)
Browse files Browse the repository at this point in the history
* chore(mesh-wide): prevent empty objects

* chore(mesh-wide): prevent undefined

* chore(mesh-wide): improve isEmpty
  • Loading branch information
selankon authored Sep 4, 2024
1 parent 03cdeaf commit 75c87fc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ export const mergeLinksAndCoordinates = <T extends LinkType>(
// Find destination link info from shared state
let dest: IBaseLink<T>;
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] };
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/utils/utils.tsx
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 75c87fc

Please sign in to comment.