From 48addae20b0079e2a3bbc2083cbe3e69234f3330 Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Wed, 23 Jun 2021 16:10:35 +0000 Subject: [PATCH] tippyjs: Fix traceback on reaction tooltip. It can happen that reactions are re-rendered while we are in the process of showing tooltip for them. In that case, we setup MutationObserver for an element not present in DOM which results in weird behaviour. We avoid it by checking the element again before setting up MutationObserver for it. See https://chat.zulip.org/#narrow/stream/6-frontend/topic /tippy.20bug/near/1206316 for details on the issue. --- static/js/tippyjs.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/static/js/tippyjs.js b/static/js/tippyjs.js index b16246378a..aaead56882 100644 --- a/static/js/tippyjs.js +++ b/static/js/tippyjs.js @@ -65,6 +65,15 @@ export function initialize() { // We target the message table and check for removal of it, it's children // and the reactions individually down in the subtree. const target_node = elem.parents(".message_table.focused_table").get(0); + if (!target_node) { + // The `reaction` was removed from DOM before we reached here. + // In that case, we simply hide the tooltip. + // We have to be smart about hiding the instance, so we hide it as soon + // as it is displayed. + setTimeout(instance.hide, 0); + return; + } + const nodes_to_check_for_removal = [ elem.parents(".recipient_row").get(0), elem.parents(".message_reactions").get(0), @@ -87,7 +96,9 @@ export function initialize() { }, onHidden(instance) { instance.destroy(); - observer.disconnect(); + if (observer) { + observer.disconnect(); + } }, appendTo: () => document.body, });