Skip to content

Commit 8581556

Browse files
crisbetojosephperrott
authored andcommitted
fix(form-field): infinite loop with zone-patch-rxjs (#15335)
Fixes the form field being thrown into an infinite loop when `zone-patch-rxjs` is included in the page. Fixes #15331.
1 parent 81a73c6 commit 8581556

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/lib/form-field/form-field.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,18 @@ export class MatFormField extends _MatFormFieldMixinBase
302302

303303
// @breaking-change 7.0.0 Remove this check once _ngZone is required. Also reconsider
304304
// whether the `ngAfterContentChecked` below is still necessary.
305-
if (this._ngZone) {
306-
this._ngZone.onStable.asObservable().pipe(takeUntil(this._destroyed)).subscribe(() => {
307-
if (this._outlineGapCalculationNeededOnStable) {
308-
this.updateOutlineGap();
309-
}
305+
const zone = this._ngZone;
306+
307+
if (zone) {
308+
// Note that we have to run outside of the `NgZone` explicitly,
309+
// in order to avoid throwing users into an infinite loop
310+
// if `zone-patch-rxjs` is included.
311+
zone.runOutsideAngular(() => {
312+
zone.onStable.asObservable().pipe(takeUntil(this._destroyed)).subscribe(() => {
313+
if (this._outlineGapCalculationNeededOnStable) {
314+
this.updateOutlineGap();
315+
}
316+
});
310317
});
311318
}
312319

0 commit comments

Comments
 (0)