Skip to content

@boundary keeps subscriptions alive after a sibling constructor throws #72210

Backlog

Description

@SkyZeroZx

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);
}
  1. Wait for Retry.
  2. Click Retry once and wait for the fallback again.
  3. 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.

Activity

  1. added
    area: core
    on Nov 25, 2026
  2. added this to the needsTriage milestone on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: core

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions