-
Notifications
You must be signed in to change notification settings - Fork 5k
Closed
Labels
Description
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
- Navigate to Notifications page.
- Click on buttons to generate a few notifications.
- Navigate to Dashboard page.
- After a second the warning is displayed.
Resolution
- Notifications.jsx: Add
alertTimeout = nullmember. - Notifications.jsx: Add
clearAlertTimeoutfunction:
clearAlertTimeout() {
if (this.alertTimeout !== null) {
clearTimeout(this.alertTimeout);
}
}
- Notifications.jsx: Add
componentWillUnmount()function:
componentWillUnmount() {
this.clearAlertTimeout();
}
- Notifications.jsx: Update
showNotificationfunction:
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
);
}
Reactions are currently unavailable