Skip to content

Commit 61dada8

Browse files
crisbetotinayuangao
authored andcommitted
fix(chip-list): stateChanges stream not being completed (#8636)
Fixes the `stateChanges` subject not being completed, potentially causing a memory leak if the subscribers forget to unsubscribe.
1 parent bec4cfe commit 61dada8

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/lib/chips/chip-list.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,15 @@ describe('MatChipList', () => {
346346
});
347347
});
348348

349+
it('should complete the stateChanges stream on destroy', () => {
350+
const spy = jasmine.createSpy('stateChanges complete');
351+
const subscription = chipListInstance.stateChanges.subscribe(undefined, undefined, spy);
352+
353+
fixture.destroy();
354+
expect(spy).toHaveBeenCalled();
355+
subscription.unsubscribe();
356+
});
357+
349358
});
350359

351360
describe('selection logic', () => {

src/lib/chips/chip-list.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ export class MatChipList extends _MatChipListMixinBase implements MatFormFieldCo
376376
this._changeSubscription.unsubscribe();
377377
}
378378
this._dropSubscriptions();
379+
this.stateChanges.complete();
379380
}
380381

381382

0 commit comments

Comments
 (0)