From c0b64a2db35df22d0b97fc7832fa1f81667bad10 Mon Sep 17 00:00:00 2001 From: Karl Seamon Date: Mon, 10 Feb 2025 15:48:57 -0500 Subject: [PATCH] perf(multiple): Don't double-inject the style loader. inject() is pretty cheap, but not free. --- src/material/badge/badge.ts | 5 +++-- src/material/chips/chip.ts | 5 +++-- src/material/core/option/option.ts | 5 +++-- src/material/stepper/step-header.ts | 5 +++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/material/badge/badge.ts b/src/material/badge/badge.ts index 7c48d1e6033a..1efdeb72ba23 100644 --- a/src/material/badge/badge.ts +++ b/src/material/badge/badge.ts @@ -151,8 +151,9 @@ export class MatBadge implements OnInit, OnDestroy { constructor(...args: unknown[]); constructor() { - inject(_CdkPrivateStyleLoader).load(_MatBadgeStyleLoader); - inject(_CdkPrivateStyleLoader).load(_VisuallyHiddenLoader); + const styleLoader = inject(_CdkPrivateStyleLoader); + styleLoader.load(_MatBadgeStyleLoader); + styleLoader.load(_VisuallyHiddenLoader); if (typeof ngDevMode === 'undefined' || ngDevMode) { const nativeElement = this._elementRef.nativeElement; diff --git a/src/material/chips/chip.ts b/src/material/chips/chip.ts index 779c1c55916f..c49f81fd07d1 100644 --- a/src/material/chips/chip.ts +++ b/src/material/chips/chip.ts @@ -242,8 +242,9 @@ export class MatChip implements OnInit, AfterViewInit, AfterContentInit, DoCheck constructor(...args: unknown[]); constructor() { - inject(_CdkPrivateStyleLoader).load(_StructuralStylesLoader); - inject(_CdkPrivateStyleLoader).load(_VisuallyHiddenLoader); + const styleLoader = inject(_CdkPrivateStyleLoader); + styleLoader.load(_StructuralStylesLoader); + styleLoader.load(_VisuallyHiddenLoader); const animationMode = inject(ANIMATION_MODULE_TYPE, {optional: true}); this._animationsDisabled = animationMode === 'NoopAnimations'; this._monitorFocus(); diff --git a/src/material/core/option/option.ts b/src/material/core/option/option.ts index 3b5b211f206c..1edd226780ed 100644 --- a/src/material/core/option/option.ts +++ b/src/material/core/option/option.ts @@ -139,8 +139,9 @@ export class MatOption implements FocusableOption, AfterViewChecked, On constructor(...args: unknown[]); constructor() { - inject(_CdkPrivateStyleLoader).load(_StructuralStylesLoader); - inject(_CdkPrivateStyleLoader).load(_VisuallyHiddenLoader); + const styleLoader = inject(_CdkPrivateStyleLoader); + styleLoader.load(_StructuralStylesLoader); + styleLoader.load(_VisuallyHiddenLoader); this._signalDisableRipple = !!this._parent && isSignal(this._parent.disableRipple); } diff --git a/src/material/stepper/step-header.ts b/src/material/stepper/step-header.ts index 38240eb3ced8..19efe841a043 100644 --- a/src/material/stepper/step-header.ts +++ b/src/material/stepper/step-header.ts @@ -88,8 +88,9 @@ export class MatStepHeader extends CdkStepHeader implements AfterViewInit, OnDes constructor() { super(); - inject(_CdkPrivateStyleLoader).load(_StructuralStylesLoader); - inject(_CdkPrivateStyleLoader).load(_VisuallyHiddenLoader); + const styleLoader = inject(_CdkPrivateStyleLoader); + styleLoader.load(_StructuralStylesLoader); + styleLoader.load(_VisuallyHiddenLoader); const changeDetectorRef = inject(ChangeDetectorRef); this._intlSubscription = this._intl.changes.subscribe(() => changeDetectorRef.markForCheck()); }