Skip to content

Commit

Permalink
fix: performance issue caused by excessive use of clearTimeout/Interval
Browse files Browse the repository at this point in the history
  • Loading branch information
astei committed Sep 21, 2021
1 parent 8f22191 commit 22aea50
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,10 +587,13 @@ class ReactTooltip extends React.Component {
}
};

clearTimeout(this.delayShowLoop);
if (this.delayShowLoop) {
clearTimeout(this.delayShowLoop);
}
if (delayTime) {
this.delayShowLoop = setTimeout(updateState, delayTime);
} else {
this.delayShowLoop = null;
updateState();
}
}
Expand Down Expand Up @@ -737,10 +740,22 @@ class ReactTooltip extends React.Component {
* CLear all kinds of timeout of interval
*/
clearTimer() {
clearTimeout(this.delayShowLoop);
clearTimeout(this.delayHideLoop);
clearTimeout(this.delayReshow);
clearInterval(this.intervalUpdateContent);
if (this.delayShowLoop) {
clearTimeout(this.delayShowLoop);
this.delayShowLoop = null;
}
if (this.delayHideLoop) {
clearTimeout(this.delayHideLoop);
this.delayHideLoop = null;
}
if (this.delayReshow) {
clearTimeout(this.delayReshow);
this.delayReshow = null;
}
if (this.intervalUpdateContent) {
clearInterval(this.intervalUpdateContent);
this.intervalUpdateContent = null;
}
}

hasCustomColors() {
Expand Down

0 comments on commit 22aea50

Please sign in to comment.