Skip to content

Commit e94b7bd

Browse files
crisbetoannieyw
authored andcommitted
fix(material-experimental/mdc-progress-bar): run resize observer outside zone (#21564)
Runs the `ResizeObserver` from the progress bar outside of the `NgZone` so that it doesn't trigger change detection. (cherry picked from commit bd2c324)
1 parent f18c416 commit e94b7bd

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/material-experimental/mdc-progress-bar/progress-bar.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,19 @@ export class MatProgressBar extends _MatProgressBarMixinBase implements AfterVie
101101
(window as unknown as WithMDCResizeObserver).ResizeObserver;
102102

103103
if (resizeObserverConstructor) {
104-
const observer = new resizeObserverConstructor(callback);
105-
106-
// Internal client users found production errors where `observe` was not a function
107-
// on the constructed `observer`. This should not happen, but adding this check for this
108-
// edge case.
109-
if (typeof observer.observe === 'function') {
110-
observer.observe(this._rootElement);
111-
return observer;
112-
}
104+
return this._ngZone.runOutsideAngular(() => {
105+
const observer = new resizeObserverConstructor(callback);
106+
107+
// Internal client users found production errors where `observe` was not a function
108+
// on the constructed `observer`. This should not happen, but adding this check for this
109+
// edge case.
110+
if (typeof observer.observe === 'function') {
111+
observer.observe(this._rootElement);
112+
return observer;
113+
}
114+
115+
return null;
116+
});
113117
}
114118

115119
return null;

0 commit comments

Comments
 (0)