diff --git a/app/utils/tree.ts b/app/utils/tree.ts index e5b464f8a..89b6e4073 100644 --- a/app/utils/tree.ts +++ b/app/utils/tree.ts @@ -17,9 +17,11 @@ export const flattenTree = (root: NavigationNode) => { export const ancestors = (node: NavigationNode | null) => { const ancestors: NavigationNode[] = []; - while (node !== null) { - ancestors.unshift(node); - node = node.parent as NavigationNode | null; + if (node) { + while (node.parent !== null) { + ancestors.unshift(node.parent as NavigationNode); + node = node.parent as NavigationNode; + } } return ancestors; };