Skip to content

Commit

Permalink
fix Tooltip component complete handlers [twbs#37474]
Browse files Browse the repository at this point in the history
* ensure `complete` handlers for `show` and `hide` check if the commponent was disposed
* what can happen is the element can get removed from the DOM and the tooltip would get disposed
* when the complete handler would run at a later point the component would be disposed and would throw various null related exceptions
  • Loading branch information
yads committed Sep 19, 2024
1 parent 523493d commit 666a3ae
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions js/src/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ class Tooltip extends BaseComponent {
}

const complete = () => {
// component disposed
if (!this._element) {
return
}

EventHandler.trigger(this._element, this.constructor.eventName(EVENT_SHOWN))

if (this._isHovered === false) {
Expand Down Expand Up @@ -266,6 +271,11 @@ class Tooltip extends BaseComponent {
this._isHovered = null // it is a trick to support manual triggering

const complete = () => {
// component disposed
if (!this._element) {
return
}

if (this._isWithActiveTrigger()) {
return
}
Expand Down

0 comments on commit 666a3ae

Please sign in to comment.