Repository navigation
Backlog
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