flauc / angular2-notifications

A light and easy to use notifications library for Angular.
https://stackblitz.com/edit/angular2-notifications-example
MIT License
746 stars 164 forks source link

ViewDeestroyedError when click closing notification #296

Open CHBaker opened 6 years ago

CHBaker commented 6 years ago

Hey, I'm getting this error when I click the notification for it to disappear.

Uncaught Error: ViewDestroyedError: Attempt to use a destroyed view: detectChanges
    at viewDestroyedError (core.js:9800)
    at Object.debugUpdateDirectives [as updateDirectives] (core.js:14652)
    at checkAndUpdateView (core.js:13802)
    at callWithDebugContext (core.js:15056)
    at Object.debugCheckAndUpdateView [as checkAndUpdateView] (core.js:14593)
    at ViewRef_.detectChanges (core.js:11577)
    at eval (angular2-notifications.umd.js:535) <----------- HERE
    at ZoneDelegate.invoke (zone.js:388)
    at Object.onInvoke (core.js:4749)
    at ZoneDelegate.invoke (zone.js:387)

This is very bad for performance as this error hits 365 times in my app because it executes change detection though the entire component tree. This error is coming from Angular's changed detection running right after it's destroyed, looking for it. I'm not sure how to fix it though, or prevent it maybe in the source code for angular2-notifications

pmitrifork commented 6 years ago

I had the same issue today.

CHBaker commented 6 years ago

I'd be happy to submit a pull request, I just couldn't find in the source code where I could add the onDestroy hook and what to unsubscribe from

Frisky- commented 6 years ago

Any fix for that ?

flauc commented 6 years ago

I'm unable to recreate this one. If someone can help set up the recreated error https://stackblitz.com. I can start debugging.

CHBaker commented 6 years ago

I can try to recreate it next week, I know it has to do with a subscription that is not unsubscribed from in the source code, It might be caused by lazy loaded routes

davidalee commented 6 years ago

I don't know if it's necessarily related to lazy loaded routes as I'm also seeing this error and do not have lazy loaded routes in my app.

I'm not able to reproduce this issue reliably, but when it does fail, it fails spectacularly and crashes the entire app.

flauc commented 6 years ago

yes @davidalee you're right as far as I can tell it isn't connected. It looks like it errors out when the notification is manually destroyed at the same time as it's being animated out.