tippy: Check if reaction still exists in DOM before showing tooltip.

This avoids an error being triggered if `instance.reference` gets
remvoed from the DOM and `rows.get_message_id` is called on it in
`onShow` later.

This is an untested bug fix since I was not able to reproduce
this on live server or locally.
This commit is contained in:
Aman Agrawal 2022-10-18 05:36:46 +00:00 committed by Tim Abbott
parent 59e7741055
commit abec99fe0c
1 changed files with 6 additions and 0 deletions

View File

@ -114,6 +114,11 @@ export function initialize() {
target: ".message_reaction, .message_reactions .reaction_button",
placement: "bottom",
onShow(instance) {
if (!document.body.contains(instance.reference)) {
// It is possible for reaction to be removed before `onShow` is triggered,
// so, we check if the element exists before proceeding.
return false;
}
const $elem = $(instance.reference);
if (!instance.reference.classList.contains("reaction_button")) {
const local_id = $elem.attr("data-reaction-id");
@ -130,6 +135,7 @@ export function initialize() {
$elem.get(0),
];
hide_tooltip_if_reference_removed(target, config, instance, nodes_to_check_for_removal);
return true;
},
onHidden(instance) {
instance.destroy();