Repository navigation
In progress
Labels
area: coreIssues related to the framework runtime
Milestone
Description
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
The boundary shows the fallback when a constructor throws inside @defer. But a component created before the throwing sibling keeps its subscription alive, even with takeUntilDestroyed(). Each $reset() adds another one.
LiveOrders subscribes to OrdersService.updates. OrderTotal then throws because USDD is an invalid currency code.
import { Component, Service, inject, signal } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { Subject } from 'rxjs';
@Service()
export class OrdersService {
readonly orderCount = 3;
readonly total = 100;
readonly updates = new Subject<void>();
readonly count = signal(0);
}
@Component({ selector: 'live-orders', template: '<p>Orders: {{ orders.orderCount }}</p>' })
class LiveOrders {
readonly orders = inject(OrdersService);
constructor() {
this.orders.updates
.pipe(takeUntilDestroyed())
.subscribe(() => this.orders.count.update((value) => value + 1));
}
}
@Component({
selector: 'order-total',
template: '<p>Total: {{ formatter.format(orders.total) }}</p>',
})
class OrderTotal {
readonly orders = inject(OrdersService);
readonly formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USDD',
});
}
@Component({
imports: [LiveOrders, OrderTotal],
selector: 'app-root',
template: `
@boundary {
@defer (on immediate) {
<live-orders />
<order-total />
}
} @error {
<p>Could not load orders.</p>
<button (click)="$reset()">Retry</button>
}
<button (click)="orders.updates.next()">Emit</button>
<p id="notifications">Notifications: {{ orders.count() }}</p>
`,
})
export class App {
readonly orders = inject(OrdersService);
}- Wait for Retry.
- Click Retry once and wait for the fallback again.
- Click Emit once.
I expected Notifications: 0. I get Notifications: 2: both failed attempts still react to the same emission.
Anything else?
This also happens without @defer. Moving the error to ngOnInit cleans up both subscriptions.
In the constructor case, DestroyRef.onDestroy, ngOnDestroy, and subscription finalization never run for LiveOrders. Destroying the fixture afterward doesn't clean them up either.
Metadata
Metadata
Assignees
Labels
area: coreIssues related to the framework runtime
Activity
JeanMeche commentedon Nov 26, 2026
When a threw my agent at it I got #72222, looking at the code it reminded me of #70406.
The question here is should
@boundarycover errors thrown at construction time. As you mention when throwing inngOnInitthe component is cleaned up correctly. This is expected as hooks are part of rendering.SkyZeroZx commentedon Nov 26, 2026
As I understand it, or at least for the case in our own codebase in Angular, I think
@boundaryshould/must cover errors in the constructor since that was the intended behavior. However, we can add it as a limitation in the documentation, but I don't think that can be the case because it can be a common case and break the expected behavior for the users/agents.Also, it's a bit odd this behavior , if we do a subscription to something , we can get duplicated and cause unexpected bugs