Skip to content

Commit 22aea50

Browse files
committed
fix: performance issue caused by excessive use of clearTimeout/Interval
1 parent 8f22191 commit 22aea50

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/index.js

+20-5
Original file line numberDiff line numberDiff line change
@@ -587,10 +587,13 @@ class ReactTooltip extends React.Component {
587587
}
588588
};
589589

590-
clearTimeout(this.delayShowLoop);
590+
if (this.delayShowLoop) {
591+
clearTimeout(this.delayShowLoop);
592+
}
591593
if (delayTime) {
592594
this.delayShowLoop = setTimeout(updateState, delayTime);
593595
} else {
596+
this.delayShowLoop = null;
594597
updateState();
595598
}
596599
}
@@ -737,10 +740,22 @@ class ReactTooltip extends React.Component {
737740
* CLear all kinds of timeout of interval
738741
*/
739742
clearTimer() {
740-
clearTimeout(this.delayShowLoop);
741-
clearTimeout(this.delayHideLoop);
742-
clearTimeout(this.delayReshow);
743-
clearInterval(this.intervalUpdateContent);
743+
if (this.delayShowLoop) {
744+
clearTimeout(this.delayShowLoop);
745+
this.delayShowLoop = null;
746+
}
747+
if (this.delayHideLoop) {
748+
clearTimeout(this.delayHideLoop);
749+
this.delayHideLoop = null;
750+
}
751+
if (this.delayReshow) {
752+
clearTimeout(this.delayReshow);
753+
this.delayReshow = null;
754+
}
755+
if (this.intervalUpdateContent) {
756+
clearInterval(this.intervalUpdateContent);
757+
this.intervalUpdateContent = null;
758+
}
744759
}
745760

746761
hasCustomColors() {

0 commit comments

Comments
 (0)