From 5191a80a3af6c0b3ea3d6f9ea3b9d5cb1f9b5b8e Mon Sep 17 00:00:00 2001 From: Sayam Samal Date: Wed, 3 Jul 2024 19:56:45 +0530 Subject: [PATCH] playground_popover: Fix bug where the playground popover doesn't reopen. This commit fixes a bug where the popover doesn't reopen after it's closed. The bug was caused since `playground_links_popover_instance` wasn't being set to `null` after the popover was closed, which led the `is_open` function to return `true` even when the popover was closed. --- web/src/playground_links_popover.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) 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; }