Skip to content

Commit 691a7ad

Browse files
committed
move @Ouput() back outside the zone to prevent breaking changes
1 parent 7d8ab68 commit 691a7ad

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/cdk/observers/observe-content.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
Injectable,
1616
Input,
1717
NgModule,
18+
NgZone,
1819
OnDestroy,
1920
Output,
2021
} from '@angular/core';
@@ -153,7 +154,8 @@ export class CdkObserveContent implements AfterContentInit, OnDestroy {
153154

154155
private _currentSubscription: Subscription | null = null;
155156

156-
constructor(private _contentObserver: ContentObserver, private _elementRef: ElementRef) {}
157+
constructor(private _contentObserver: ContentObserver, private _elementRef: ElementRef,
158+
private _ngZone: NgZone) {}
157159

158160
ngAfterContentInit() {
159161
if (!this._currentSubscription && !this.disabled) {
@@ -168,8 +170,15 @@ export class CdkObserveContent implements AfterContentInit, OnDestroy {
168170
private _subscribe() {
169171
this._unsubscribe();
170172
const stream = this._contentObserver.observe(this._elementRef.nativeElement);
171-
this._currentSubscription = (this.debounce ? stream.pipe(debounceTime(this.debounce)) : stream)
172-
.subscribe(mutations => this.event.next(mutations));
173+
174+
// TODO(mmalerba): We shouldn't be emitting on this @Output() outside the zone.
175+
// Consider brining it back inside the zone next time we're making breaking changes.
176+
// Bringing it back inside can cause things like infinite change detection loops and changed
177+
// after checked errors if people's code isn't handling it properly.
178+
this._ngZone.runOutsideAngular(() => {
179+
this._currentSubscription =
180+
(this.debounce ? stream.pipe(debounceTime(this.debounce)) : stream).subscribe(this.event);
181+
});
173182
}
174183

175184
private _unsubscribe() {

0 commit comments

Comments
 (0)