UntilDestroy seems to be statefull
See original GitHub issueIn our application we are using local subscriptions to move from one url to another. For our use-case it´s fine. Now we have defined this in our goal component (StartComponent -> GoalComponent):
this.service.localData$
.pipe(untilDestroyed(this))
.subscribe((data: any[]) => {
if (data?.length > 0) {
this.createTable();
} else {
this.goBack();
}
});
This gets called in the ngOnInit of the GoalComponent. So in the first case everything works fine. Now when the user navigates back through browser navigation (GoalComponent --> StartComponent) and then moves foreward again (StartComponent -> GoalComponent) with selecting an empty array. The StartComponent refuses to navigate to the GoalComponent:
if (moreThanOneSelected) {
this.goTo('goal');
} else {
this.alert('Some Text');
}
So there shouldn´t be any kind of navigation. But here comes the problem. The subscription of localData$
in the GoalComponent is still active and fires the goBack
method.
I compared it with the classic takeUntil()
approach and this one works. So the untilDestroyed is not ending the subscription when the component gets destroyed.
We use:
- Angular 10
- Ivy
- the simplest approach mentioned here with
@UntilDestroy()
and as pipe operatoruntilDestroyed(this)
Do you need some more information?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:8
You have to create a minimal project, push it to GitHub and paste a link here. Everyone who sees that issue will be able to debug your example and probably provide a fix.
Closing that issue as not reproducible, there seems to be no activity since it’s opened and the reproduction is not provided yet. Feel free to re-open this issue with reproducible example.