gilsdav / ngx-translate-router

Translate routes using ngx-translate
131 stars 43 forks source link

ViewDestroyedError: Attempt to use a destroyed view: detectChanges #106

Open BojanKogoj opened 3 years ago

BojanKogoj commented 3 years ago

I managed to get this exception in LocalizeRouterPipe, but hard to reproduce.

exception

With current implementation

https://github.com/gilsdav/ngx-translate-router/blob/86d2e52f62d61d59d3b5d4c954f4a10f84ffda59/projects/ngx-translate-router/src/lib/localize-router.pipe.ts#L51-L56

I can only assume it was destroyed while in setTimeout. This was introduced in https://github.com/gilsdav/ngx-translate-router/commit/851563ab6f17bf748418f32fd22c97da01436efa.

I suggest we check if view was destroyed before calling .detectChanges() stackoverflow

setTimeout(() => {
  if (this._ref && !(this._ref as ViewRef).destroyed) {
    this._ref.detectChanges();
  }
}, 0)
gilsdav commented 3 years ago

Is it compatible with and without Ivy ?