From a81774984dd0808e601f567ffb808c65aeedfcb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiktor=20O=C5=BCga?= Date: Thu, 15 Sep 2016 09:01:28 +0200 Subject: [PATCH 1/2] Fixes #1 --- src/index.jsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/index.jsx b/src/index.jsx index da05722..e9b3ca2 100644 --- a/src/index.jsx +++ b/src/index.jsx @@ -11,7 +11,7 @@ class CircularProgressbar extends React.Component { componentDidMount() { if (this.props.initialAnimation) { - setTimeout(() => { + this.initialTimeout = setTimeout(() => { window.requestAnimationFrame(() => { this.setState({ percentage: this.props.percentage, @@ -27,6 +27,10 @@ class CircularProgressbar extends React.Component { }); } + componentWillUnmount() { + clearTimeout(this.initialTimeout); + } + render() { const radius = (50 - this.props.strokeWidth / 2); const pathDescription = ` From 5c74157d817e77f1010864df8748ced69da5beb0 Mon Sep 17 00:00:00 2001 From: Kevin Qi Date: Tue, 8 Nov 2016 11:24:33 -0500 Subject: [PATCH 2/2] Fix issue where window.requestAnimationFrame callback can still be invoked after component is unmounted, causing an error --- src/index.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.jsx b/src/index.jsx index e9b3ca2..5588408 100644 --- a/src/index.jsx +++ b/src/index.jsx @@ -12,7 +12,7 @@ class CircularProgressbar extends React.Component { componentDidMount() { if (this.props.initialAnimation) { this.initialTimeout = setTimeout(() => { - window.requestAnimationFrame(() => { + this.requestAnimationFrame = window.requestAnimationFrame(() => { this.setState({ percentage: this.props.percentage, }); @@ -29,6 +29,7 @@ class CircularProgressbar extends React.Component { componentWillUnmount() { clearTimeout(this.initialTimeout); + window.cancelAnimationFrame(this.requestAnimationFrame); } render() {