Skip to content

Commit 66a3232

Browse files
atscottcrisbeto
authored andcommitted
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. (cherry picked from commit 96c1b85)
1 parent 6103cd5 commit 66a3232

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
@@ -33,7 +33,6 @@ import {Observable, Subject} from 'rxjs';
3333
import {AriaLivePoliteness} from '@angular/cdk/a11y';
3434
import {Platform} from '@angular/cdk/platform';
3535
import {AnimationEvent} from '@angular/animations';
36-
import {take} from 'rxjs/operators';
3736
import {MatSnackBarConfig} from './snack-bar-config';
3837

3938
let uniqueId = 0;
@@ -228,15 +227,13 @@ export class MatSnackBarContainer extends BasePortalOutlet implements OnDestroy
228227
}
229228

230229
/**
231-
* Waits for the zone to settle before removing the element. Helps prevent
232-
* errors where we end up removing an element which is in the middle of an animation.
230+
* Removes the element in a microtask. Helps prevent errors where we end up
231+
* removing an element which is in the middle of an animation.
233232
*/
234233
private _completeExit() {
235-
this._ngZone.onMicrotaskEmpty.pipe(take(1)).subscribe(() => {
236-
this._ngZone.run(() => {
237-
this._onExit.next();
238-
this._onExit.complete();
239-
});
234+
queueMicrotask(() => {
235+
this._onExit.next();
236+
this._onExit.complete();
240237
});
241238
}
242239

0 commit comments

Comments
 (0)