From 6fdd8e15d475efb99ebf14ffb349c5fbdc834ae6 Mon Sep 17 00:00:00 2001 From: Drew Hess Date: Sat, 4 May 2024 18:17:46 +0100 Subject: [PATCH] fix: fix a few undefined cases in our vendored `tidy.ts` This is just an expedient fix. A proper fix is tracked in: https://github.com/hackworthltd/primer-app/issues/1189 Signed-off-by: Drew Hess --- src/components/TreeReactFlow/tidy.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/components/TreeReactFlow/tidy.ts b/src/components/TreeReactFlow/tidy.ts index e4d2cf40..bfb52d95 100644 --- a/src/components/TreeReactFlow/tidy.ts +++ b/src/components/TreeReactFlow/tidy.ts @@ -116,10 +116,18 @@ export class TidyLayout extends Disposable { this.tidy.layout(); const positions = this.tidy.get_pos(); for (let i = 0; i < positions.length; i += 3) { - const id = positions[i] | 0; + // Better error handling needed here when the id is undefined. + // + // https://github.com/hackworthltd/primer-app/issues/1189 + const id = positions[i] || 0; const node = this.idToNode.get(id)!; - node.x = positions[i + 1]; - node.y = positions[i + 2]; + + // Also need better error handling here when the node's x or y + // position is undefined. + // + // https://github.com/hackworthltd/primer-app/issues/1189 + node.x = positions[i + 1] || 0; + node.y = positions[i + 2] || 0; } }