diff --git a/web/src/playground_links_popover.ts b/web/src/playground_links_popover.ts index 1ab82a2040..f6eff373f7 100644 --- a/web/src/playground_links_popover.ts +++ b/web/src/playground_links_popover.ts @@ -12,7 +12,7 @@ import * as ui_util from "./ui_util"; type RealmPlaygroundWithURL = RealmPlayground & {playground_url: string}; -let playground_links_popover_instance: tippy.Instance; +let playground_links_popover_instance: tippy.Instance | null = null; // Playground_store contains all the data we need to generate a popover of // playground links for each code block. The element is the target element @@ -63,16 +63,19 @@ export function is_open(): boolean { } export function hide(): void { - if (is_open()) { - $(playground_links_popover_instance.reference) - .parent() - .removeClass("active-playground-links-reference"); - playground_links_popover_instance.destroy(); + if (!playground_links_popover_instance) { + return; } + + $(playground_links_popover_instance.reference) + .parent() + .removeClass("active-playground-links-reference"); + playground_links_popover_instance.destroy(); + playground_links_popover_instance = null; } function get_playground_links_popover_items(): JQuery | undefined { - if (!is_open()) { + if (!playground_links_popover_instance) { blueslip.error("Trying to get menu items when playground links popover is closed."); return undefined; }