Skip to content

Commit 96c1b85

Browse files
authored
refactor(material/snack-bar): Remove NgZone.onMicrotaskEmpty dependency (#28370)
`onMicrotaskEmpty` will not emit when an application is using `NoopNgZone`. There wasn't a test around this bit of code when it was added so I can't completely sure this doesn't break anything. It's unclear to me whether it's meant to wait for rendering or just meant to be async. It's possible that simply making the code execute in the microtask queue will have the same overall effect as before.
1 parent ae89329 commit 96c1b85

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/material/snack-bar/snack-bar-container.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import {Observable, Subject} from 'rxjs';
3232
import {AriaLivePoliteness} from '@angular/cdk/a11y';
3333
import {Platform} from '@angular/cdk/platform';
3434
import {AnimationEvent} from '@angular/animations';
35-
import {take} from 'rxjs/operators';
3635
import {MatSnackBarConfig} from './snack-bar-config';
3736

3837
let uniqueId = 0;
@@ -231,15 +230,13 @@ export class MatSnackBarContainer extends BasePortalOutlet implements OnDestroy
231230
}
232231

233232
/**
234-
* Waits for the zone to settle before removing the element. Helps prevent
235-
* errors where we end up removing an element which is in the middle of an animation.
233+
* Removes the element in a microtask. Helps prevent errors where we end up
234+
* removing an element which is in the middle of an animation.
236235
*/
237236
private _completeExit() {
238-
this._ngZone.onMicrotaskEmpty.pipe(take(1)).subscribe(() => {
239-
this._ngZone.run(() => {
240-
this._onExit.next();
241-
this._onExit.complete();
242-
});
237+
queueMicrotask(() => {
238+
this._onExit.next();
239+
this._onExit.complete();
243240
});
244241
}
245242

0 commit comments

Comments
 (0)