Skip to content

Commit

Permalink
perf(multiple): Don't double-inject the style loader. (#30467)
Browse files Browse the repository at this point in the history
inject() is pretty cheap, but not free.
  • Loading branch information
kseamon authored Feb 11, 2025
1 parent 4c3206c commit 1ddb9cf
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/material/badge/badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/material/chips/chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions src/material/core/option/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ export class MatOption<T = any> 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);
}

Expand Down
5 changes: 3 additions & 2 deletions src/material/stepper/step-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit 1ddb9cf

Please sign in to comment.