Skip to content

Commit

Permalink
fix(material-experimental/mdc-progress-bar): run resize observer outs…
Browse files Browse the repository at this point in the history
…ide zone (#21564)

Runs the `ResizeObserver` from the progress bar outside of the `NgZone` so that it doesn't
trigger change detection.
  • Loading branch information
crisbeto authored Mar 5, 2021
1 parent be508da commit bd2c324
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/material-experimental/mdc-progress-bar/progress-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,19 @@ export class MatProgressBar extends _MatProgressBarMixinBase implements AfterVie
(window as unknown as WithMDCResizeObserver).ResizeObserver;

if (resizeObserverConstructor) {
const observer = new resizeObserverConstructor(callback);

// Internal client users found production errors where `observe` was not a function
// on the constructed `observer`. This should not happen, but adding this check for this
// edge case.
if (typeof observer.observe === 'function') {
observer.observe(this._rootElement);
return observer;
}
return this._ngZone.runOutsideAngular(() => {
const observer = new resizeObserverConstructor(callback);

// Internal client users found production errors where `observe` was not a function
// on the constructed `observer`. This should not happen, but adding this check for this
// edge case.
if (typeof observer.observe === 'function') {
observer.observe(this._rootElement);
return observer;
}

return null;
});
}

return null;
Expand Down

0 comments on commit bd2c324

Please sign in to comment.