While this type of errors can have multiple causes, in my specific case the error was caused by a race condition: parent component was listening to a BehaviorSubject in a service while a child component (in parent's <router-outlet>) was listening to routing events and subsequently updating the same BehaviorSubject.
So it was like
Parent | Child | Service |
---|---|---|
public mode: BehaviorSubject<T> = new BehaviorSubject(someVal); |
||
Parent subscribes onInit this.mode.pipe(...).subscribe(); |
Child subscribes onInit this.route.params.pipe(tap(() => this.service.setMode(someVar)).subscribe() |
public setMode(var) {this.mode.next(var)} After which parent throws error |
[fix] this.mode.pipe(observeOn(asyncScheduler),...).subscribe() |
So observeOn(asyncScheduler)
saved my day. Never heard of this pattern before, but it works just fine.