Skip to content

Commit

Permalink
fix(cdk/observers): Run content changed callback in NgZone
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalerba committed Apr 11, 2024
1 parent f10a158 commit 7a1118a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
14 changes: 3 additions & 11 deletions src/cdk/observers/observe-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
Injectable,
Input,
NgModule,
NgZone,
OnDestroy,
Output,
booleanAttribute,
Expand Down Expand Up @@ -202,7 +201,6 @@ export class CdkObserveContent implements AfterContentInit, OnDestroy {
constructor(
private _contentObserver: ContentObserver,
private _elementRef: ElementRef<HTMLElement>,
private _ngZone: NgZone,
) {}

ngAfterContentInit() {
Expand All @@ -219,15 +217,9 @@ export class CdkObserveContent implements AfterContentInit, OnDestroy {
this._unsubscribe();
const stream = this._contentObserver.observe(this._elementRef);

// TODO(mmalerba): We shouldn't be emitting on this @Output() outside the zone.
// Consider brining it back inside the zone next time we're making breaking changes.
// Bringing it back inside can cause things like infinite change detection loops and changed
// after checked errors if people's code isn't handling it properly.
this._ngZone.runOutsideAngular(() => {
this._currentSubscription = (
this.debounce ? stream.pipe(debounceTime(this.debounce)) : stream
).subscribe(this.event);
});
this._currentSubscription = (
this.debounce ? stream.pipe(debounceTime(this.debounce)) : stream
).subscribe(this.event);
}

private _unsubscribe() {
Expand Down
3 changes: 1 addition & 2 deletions tools/public_api_guard/cdk/observers.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import { AfterContentInit } from '@angular/core';
import { ElementRef } from '@angular/core';
import { EventEmitter } from '@angular/core';
import * as i0 from '@angular/core';
import { NgZone } from '@angular/core';
import { NumberInput } from '@angular/cdk/coercion';
import { Observable } from 'rxjs';
import { OnDestroy } from '@angular/core';

// @public
export class CdkObserveContent implements AfterContentInit, OnDestroy {
constructor(_contentObserver: ContentObserver, _elementRef: ElementRef<HTMLElement>, _ngZone: NgZone);
constructor(_contentObserver: ContentObserver, _elementRef: ElementRef<HTMLElement>);
get debounce(): number;
set debounce(value: NumberInput);
get disabled(): boolean;
Expand Down

0 comments on commit 7a1118a

Please sign in to comment.