From 22aea5086db47727feae609bb7a6f8e269b7f2de Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Tue, 21 Sep 2021 18:22:50 -0400 Subject: [PATCH] fix: performance issue caused by excessive use of clearTimeout/Interval --- src/index.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index 396fd633..ed9a626c 100755 --- a/src/index.js +++ b/src/index.js @@ -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(); } } @@ -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() {