Skip to content

Commit da9b7c3

Browse files
Monica Wheelerkajabi-bot
authored andcommitted
fix(tooltip): ensure valid node before removal to prevent errors
This commit fixes an issue where the `removeTooltip` function attempted to remove a tooltip element from the DOM without verifying if it was a valid child of `document.body`. The updated implementation adds a check to ensure the tooltip exists and its parent node is `document.body` before proceeding with the removal. This change prevents the "Failed to execute removeChild on Node: parameter 1 is not of type Node." error from being thrown, enhancing the robustness and reliability of tooltip removal.
1 parent 9079d49 commit da9b7c3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

packages/sage-system/lib/tooltip.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,18 @@ Sage.tooltip = (function() {
5353
positionTooltip(evt.target, tooltip, pos);
5454
}
5555

56-
5756
// Removes tooltip from DOM
5857
function removeTooltip(evt) {
59-
if (!evt.target.hasAttribute(DATA_ATTR) || !document.querySelector(SELECTOR) || !document.querySelector(`.${TOOLTIP_CLASS}`) || !evt.target.dataset.jsTooltip) return;
58+
if (!evt.target.hasAttribute(DATA_ATTR) || !document.querySelector(SELECTOR) || !document.querySelector(`.${TOOLTIP_CLASS}`) || !evt.target.dataset.jsTooltip) return;
6059

6160
window.requestAnimationFrame(function() {
62-
document.body.removeChild(document.querySelector(`.${TOOLTIP_CLASS}`));
61+
var tooltip = document.querySelector(`.${TOOLTIP_CLASS}`);
62+
if (tooltip && tooltip.parentNode === document.body) { // Ensure tooltip exists and its parent is document.body before removing
63+
document.body.removeChild(tooltip);
64+
}
6365
});
6466
}
6567

66-
6768
// Builds list of modifier classes from array of data-attributes
6869
function generateClasses(ele, evt) {
6970
ele.dataItems.forEach(function(item) {

0 commit comments

Comments
 (0)