Skip to content

Multiple subscriptions causing troubles #215

@cjblomqvist

Description

@cjblomqvist

Scenario in Angular:
Service A:

constructor() {
  this.list = this.angularfire.list('/myList');
}

Component A:

onInit() {
  this.list = this.serviceA.list;
}
<div *ngFor="let item of list | async">
  <componentB />
</div>

Component B:
<componentC />

Component C:

onInit() {
  this.list = this.serviceA.list;
}

<div *ngFor="let item of list | async">TEST</div>

Then you update one of the items in list (e.g. through Firebase admin web interface). This will cause the following:

  1. Component C will be destroyed
  2. Which causes the async pipe to unsubscribe to the this.list Observable.
  3. Due to https://github.com/angular/angularfire2/blob/master/src/utils/firebase_list_factory.ts#L139 - all listeners/subscriptions are cancelled to the ref. Since we have two listeners/subscriptions (one at Component C which should cancel, and one at Component A which should NOT cancel), this will break the app (more specifically, Component A's subscription will cancel which it shouldn't).

I'll send a PR ASAP to fix this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions