Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Notifications.jsx: Calling setState on an unmounted component. #37

Closed
W1M0R opened this issue Jun 18, 2018 · 1 comment
Closed

Notifications.jsx: Calling setState on an unmounted component. #37

W1M0R opened this issue Jun 18, 2018 · 1 comment
Labels

Comments

@W1M0R
Copy link

W1M0R commented Jun 18, 2018

Issue

Notifications not cleared between page changes, causing React warnings printed in the console:

Warning: Can't call setState (or forceUpdate) on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
in Notifications (created by WithStyles(Notifications))
in WithStyles(Notifications) (at notifications.js:8)
in NotificationsPage (created by ComponentRenderer)

Reproduce

  1. Navigate to Notifications page.
  2. Click on buttons to generate a few notifications.
  3. Navigate to Dashboard page.
  4. After a second the warning is displayed.

Resolution

  1. Notifications.jsx: Add alertTimeout = null member.
  2. Notifications.jsx: Add clearAlertTimeout function:
clearAlertTimeout() {
  if (this.alertTimeout !== null) {
    clearTimeout(this.alertTimeout);
  }
}
  1. Notifications.jsx: Add componentWillUnmount() function:
componentWillUnmount() {
  this.clearAlertTimeout();
}
  1. Notifications.jsx: Update showNotification function:
showNotification(place) {
  var x = [];
  x[place] = true;
  this.setState(x);
  this.clearAlertTimeout();
  this.alertTimeout = setTimeout(
    function() {
      x[place] = false;
      this.setState(x);
    }.bind(this),
    6000
  );
}
@einazare einazare added the bug label Jun 19, 2018
@einazare
Copy link
Contributor

Hello @W1M0R

Thank you for your interest in using our product.
We are going to address this issue on our next update.

Best,
Manu

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants