minhtranite / react-notifications

Notification component for ReactJS
https://www.npmjs.com/package/react-notifications
287 stars 64 forks source link

EventEmitter memory leak #32

Open hyperh opened 6 years ago

hyperh commented 6 years ago

I have a server side rendered app, and on my Express server, I'm getting the following error (sometimes):

(node:89538) Warning: Possible EventEmitter memory leak detected. 11 change listeners added. Use emitter.setMaxListeners() to increase limit
Warning +90ms
Possible EventEmitter memory leak detected. 11 change listeners added. Use emitter.setMaxListeners() to increase limit +7ms
Warning: Possible EventEmitter memory leak detected. 11 change listeners added. Use emitter.setMaxListeners() to increase limit
at _addListener (events.js:259:19)
at NotificationManager.addListener (events.js:275:10)
at NotificationManager.addChangeListener (/.../node_modules/react-notifications/lib/NotificationManager.js:118:12)
at NotificationContainer.componentWillMount (/.../node_modules/react-notifications/lib/NotificationContainer.js:46:40)
zsirosm commented 6 years ago

Late reply, but for anyone else wondering, as a workaround exclude <NotificationContainer /> from rendering on the server by rendering it conditionally after parent component has been mounted: (componentDidMount is not called during SSR)

class Parent extends React.Component {
  constructor() {
    super();
    this.state = {
      mounted: false,
    }
  }

  componentDidMount() {
    this.setState({ mounted: true });
  }

  render() {
    return (
      <div>
        // rest of component
        {this.state.mounted && <NotificationContainer /> }
      </div>
    )
  }
}