Skip to content

Commit 518745b

Browse files
authored
Merge pull request #720 from astei/fix/timeout-performance
fix: performance issue caused by excessive use of clearTimeout/Interval
2 parents 1983ca7 + 22aea50 commit 518745b

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

Diff for: src/index.js

+20-5
Original file line numberDiff line numberDiff line change
@@ -591,10 +591,13 @@ class ReactTooltip extends React.Component {
591591
}
592592
};
593593

594-
clearTimeout(this.delayShowLoop);
594+
if (this.delayShowLoop) {
595+
clearTimeout(this.delayShowLoop);
596+
}
595597
if (delayTime) {
596598
this.delayShowLoop = setTimeout(updateState, delayTime);
597599
} else {
600+
this.delayShowLoop = null;
598601
updateState();
599602
}
600603
}
@@ -743,10 +746,22 @@ class ReactTooltip extends React.Component {
743746
* CLear all kinds of timeout of interval
744747
*/
745748
clearTimer() {
746-
clearTimeout(this.delayShowLoop);
747-
clearTimeout(this.delayHideLoop);
748-
clearTimeout(this.delayReshow);
749-
clearInterval(this.intervalUpdateContent);
749+
if (this.delayShowLoop) {
750+
clearTimeout(this.delayShowLoop);
751+
this.delayShowLoop = null;
752+
}
753+
if (this.delayHideLoop) {
754+
clearTimeout(this.delayHideLoop);
755+
this.delayHideLoop = null;
756+
}
757+
if (this.delayReshow) {
758+
clearTimeout(this.delayReshow);
759+
this.delayReshow = null;
760+
}
761+
if (this.intervalUpdateContent) {
762+
clearInterval(this.intervalUpdateContent);
763+
this.intervalUpdateContent = null;
764+
}
750765
}
751766

752767
hasCustomColors() {

0 commit comments

Comments
 (0)