Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix mesh map #448

Merged
merged 4 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}