tooltip delay causes exception if element for which tooltip was created was removed from DOM
Created by: lddubeau
I searched previous issues, did not find one that was about this precise problem.
Versions
Browsers: Chrome 33.0.1750.152, Firefox 26.0. OS: Debian testing, as of 2014-04-03. Bootstrap: The fiddle is set to load from master. At the time of writing the commit is SHA: 4c2626fe
What steps will reproduce the problem?
-
Open this fiddle: http://jsfiddle.net/lddubeau/6yz7r/embedded/result/
-
Perform any of these:
a. In the "Independent" section, move quickly onto a button and click it.
b. In the "Mutual" section, move quickly onto a button and click it.
NOTE: You must click the button before the tooltip appears. The delay is set to 1 second in the fiddle.
What is expected to happen?
The buttons should disappear without causing an unhandled exception.
What happens instead?
An unhandled exception happens. On Chrome the message is:
Uncaught TypeError: Cannot read property 'tagName' of undefined bootstrap.js:1349
Tooltip.getPosition bootstrap.js:1349
Tooltip.show bootstrap.js:1215
(anonymous function) bootstrap.js:1159
Observations
The problem does not occur if:
- The trigger is not "delay".
- Auto placement is not used.
The unhandled exception happens because the element for which the tooltip is created is no longer in the DOM. When this.getPosition($parent)
is called, there is no parent element and an exception occurs in getPosition
.
Only the tests in the "Independent" and "Mutual" sections show the problem. The "Ancestors" section shows that if an ancestor of the element for which the tooltip is created is removed from the DOM instead of the element itself, then the show
method will go through without error.
Destroying the tooltip before removing the element for which it is created would prevent the problem. However, cases where GUI changes are triggered by automated processes (not under the control of the user) make catching the removal of such elements difficult in the general case.
Checking whether $parent
is an actual element, and bailing out of show
if it is not, is the cleaner solution.