From a347143f9c8e1ac82684d5285b6e8aaed8f35691 Mon Sep 17 00:00:00 2001 From: Sune Simonsen Date: Thu, 22 Nov 2018 13:30:21 +0100 Subject: [PATCH] fix(loaders): competing calls to requestAnimationFrame We currently have situations where we get multiple requestAnimationFrame callbacks queued up and componentWillUnmount will only cancel the latest one. This results in settings the state on an unmounted component which React warns about. --- packages/loaders/src/containers/ScheduleContainer.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/loaders/src/containers/ScheduleContainer.js b/packages/loaders/src/containers/ScheduleContainer.js index 811ebb4be7b..f0f9d697ae1 100644 --- a/packages/loaders/src/containers/ScheduleContainer.js +++ b/packages/loaders/src/containers/ScheduleContainer.js @@ -54,17 +54,16 @@ export default class ScheduleContainer extends Component { }, delayMS); } - componentDidUpdate() { - this.performAnimationFrame(); - } - componentWillUnmount() { clearTimeout(this.renderingDelayTimeout); cancelAnimationFrame(this.tick); } performAnimationFrame() { - this.tick = requestAnimationFrame(this.props.tick); + this.tick = requestAnimationFrame(timestamp => { + this.props.tick(timestamp); + this.performAnimationFrame(); + }); } render() {