From 33d442560437374d488a7ece2652b1146a721de2 Mon Sep 17 00:00:00 2001 From: Matthieu Riegler Date: Wed, 4 Mar 2026 23:26:32 +0100 Subject: [PATCH] refactor: drop `ComponentFactoryResolver` This API was deprecated in 2022 and can be replaced by passing the component type directly to `createComponent`. --- .../views/router_outlet_component.ts | 11 +--------- .../customization/customizable_component.ts | 22 +++++-------------- .../webapp/plugins/plugins_component.ts | 8 +------ 3 files changed, 7 insertions(+), 34 deletions(-) diff --git a/tensorboard/webapp/app_routing/views/router_outlet_component.ts b/tensorboard/webapp/app_routing/views/router_outlet_component.ts index db0becb2eb4..2e8b87ca173 100644 --- a/tensorboard/webapp/app_routing/views/router_outlet_component.ts +++ b/tensorboard/webapp/app_routing/views/router_outlet_component.ts @@ -15,7 +15,6 @@ limitations under the License. import { ChangeDetectionStrategy, Component, - ComponentFactoryResolver, Input, OnChanges, SimpleChanges, @@ -35,20 +34,12 @@ export class RouterOutletComponent implements OnChanges { @Input() activeNgComponent!: unknown | null; - constructor( - private readonly componentFactoryResolver: ComponentFactoryResolver - ) {} - ngOnChanges(changes: SimpleChanges) { const activeComponentChange = changes['activeNgComponent']; if (activeComponentChange) { this.routeContainer.clear(); if (activeComponentChange.currentValue) { - const componentFactory = - this.componentFactoryResolver.resolveComponentFactory( - activeComponentChange.currentValue - ); - this.routeContainer.createComponent(componentFactory); + this.routeContainer.createComponent(activeComponentChange.currentValue); } } } diff --git a/tensorboard/webapp/customization/customizable_component.ts b/tensorboard/webapp/customization/customizable_component.ts index bf8ef00229f..340783ed93f 100644 --- a/tensorboard/webapp/customization/customizable_component.ts +++ b/tensorboard/webapp/customization/customizable_component.ts @@ -12,14 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -import { - Component, - ComponentFactoryResolver, - Input, - OnInit, - Type, - ViewContainerRef, -} from '@angular/core'; +import {Component, Input, OnInit, Type, ViewContainerRef} from '@angular/core'; /** * A Component that defines a customization point. Ideal for use for small @@ -86,18 +79,13 @@ import { export class CustomizableComponent implements OnInit { @Input() customizableComponent!: Type | undefined; - constructor( - private readonly viewContainerRef: ViewContainerRef, - private readonly componentFactoryResolver: ComponentFactoryResolver - ) {} + constructor(private readonly viewContainerRef: ViewContainerRef) {} ngOnInit() { if (this.customizableComponent) { - const componentFactory = - this.componentFactoryResolver.resolveComponentFactory( - this.customizableComponent.constructor as Type - ); - this.viewContainerRef.createComponent(componentFactory); + this.viewContainerRef.createComponent( + this.customizableComponent.constructor as Type + ); } } } diff --git a/tensorboard/webapp/plugins/plugins_component.ts b/tensorboard/webapp/plugins/plugins_component.ts index eb1d608a244..4f40d1d58bc 100644 --- a/tensorboard/webapp/plugins/plugins_component.ts +++ b/tensorboard/webapp/plugins/plugins_component.ts @@ -21,7 +21,6 @@ limitations under the License. import { ChangeDetectionStrategy, Component, - ComponentFactoryResolver, ElementRef, Input, OnChanges, @@ -64,7 +63,6 @@ export enum PluginLoadState { }) export class PluginsComponent implements OnChanges { constructor( - private readonly componentFactoryResolver: ComponentFactoryResolver, private readonly pluginRegistry: PluginRegistryModule, @Optional() private readonly pluginApiHost: PluginApiHostModule ) {} @@ -230,12 +228,8 @@ export class PluginsComponent implements OnChanges { case LoadingMechanismType.NG_COMPONENT: const ngComponentClass = this.pluginRegistry.getComponent(plugin.id); if (ngComponentClass) { - const componentFactory = - this.componentFactoryResolver.resolveComponentFactory( - ngComponentClass - ); const pluginComponent = - this.ngPluginContainer.createComponent(componentFactory); + this.ngPluginContainer.createComponent(ngComponentClass); pluginElement = pluginComponent.location.nativeElement; } else { console.error(