Skip to content

Commit

Permalink
don't throw in spotlight.destroy() (#5017)
Browse files Browse the repository at this point in the history
* assert lastVisibleItem before computedHidden

* console.error instead of throw when spotlight destroy called and spotlight is not attached
  • Loading branch information
sashankaryal authored Oct 31, 2024
1 parent 1ecde84 commit 1a9c5d5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions app/packages/components/src/components/AdaptiveMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ export default function AdaptiveMenu(props: AdaptiveMenuPropsType) {
if (!containerElem) return;
hideOverflowingNodes(containerElem, (_: number, lastVisibleItemId) => {
const lastVisibleItem = itemsById[lastVisibleItemId];
const computedHidden = items.length - lastVisibleItem.index - 1;
setHidden(computedHidden);
if (lastVisibleItem?.index) {
const computedHidden = items.length - lastVisibleItem.index - 1;
setHidden(computedHidden);
}
});
}

Expand Down
3 changes: 2 additions & 1 deletion app/packages/spotlight/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ export default class Spotlight<K, V> extends EventTarget {

destroy(): void {
if (!this.attached) {
throw new Error("spotlight is not attached");
console.error("spotlight is not attached");
return;
}

this.#backward?.remove();
Expand Down

0 comments on commit 1a9c5d5

Please sign in to comment.