Skip to content

Commit

Permalink
Merge pull request #720 from astei/fix/timeout-performance
Browse files Browse the repository at this point in the history
fix: performance issue caused by excessive use of clearTimeout/Interval
  • Loading branch information
aronhelser authored Mar 10, 2022
2 parents 1983ca7 + 22aea50 commit 518745b
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 @@ -591,10 +591,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 @@ -743,10 +746,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 518745b

Please sign in to comment.