From 23d4205a9f00e516ef0778702c96349204bdfdeb Mon Sep 17 00:00:00 2001 From: Miles Malerba Date: Fri, 1 Mar 2024 00:17:54 +0000 Subject: [PATCH] refactor(material/tooltip): Remove use of zone onStable for overlay positioning --- src/material/tooltip/tooltip.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/material/tooltip/tooltip.ts b/src/material/tooltip/tooltip.ts index 9cc929e55490..718dd783c36a 100644 --- a/src/material/tooltip/tooltip.ts +++ b/src/material/tooltip/tooltip.ts @@ -5,7 +5,7 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {take, takeUntil} from 'rxjs/operators'; +import {takeUntil} from 'rxjs/operators'; import { BooleanInput, coerceBooleanProperty, @@ -31,6 +31,8 @@ import { ViewEncapsulation, inject, ANIMATION_MODULE_TYPE, + afterNextRender, + Injector, } from '@angular/core'; import {DOCUMENT, NgClass} from '@angular/common'; import {normalizePassiveListenerOptions, Platform} from '@angular/cdk/platform'; @@ -351,6 +353,8 @@ export class MatTooltip implements OnDestroy, AfterViewInit { /** Emits when the component is destroyed. */ private readonly _destroyed = new Subject(); + private _injector = inject(Injector); + constructor( private _overlay: Overlay, private _elementRef: ElementRef, @@ -678,11 +682,16 @@ export class MatTooltip implements OnDestroy, AfterViewInit { this._tooltipInstance.message = this.message; this._tooltipInstance._markForCheck(); - this._ngZone.onMicrotaskEmpty.pipe(take(1), takeUntil(this._destroyed)).subscribe(() => { - if (this._tooltipInstance) { - this._overlayRef!.updatePosition(); - } - }); + afterNextRender( + () => { + if (this._tooltipInstance) { + this._overlayRef!.updatePosition(); + } + }, + { + injector: this._injector, + }, + ); } }