Skip to content

Commit 38f46b6

Browse files
committed
refactor(core): remove ComponentFactoryResolver usages
This API was deprecated for a longtime, and was remove by angular#68055 from the public API. We do have alternatives to this old API, so we can entirely remove it to spare some bytes
1 parent a89b565 commit 38f46b6

33 files changed

Lines changed: 155 additions & 896 deletions

goldens/public-api/core/errors.api.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,6 @@ export const enum RuntimeErrorCode {
140140
// (undocumented)
141141
NO_BINDING_TARGET = 315,
142142
// (undocumented)
143-
NO_COMPONENT_FACTORY_FOUND = 917,
144-
// (undocumented)
145143
NO_SUPPORTING_DIFFER_FACTORY = 901,
146144
// (undocumented)
147145
OUTPUT_REF_DESTROYED = 953,

goldens/public-api/core/index.api.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,8 +1273,6 @@ export abstract class NgModuleFactory<T> {
12731273

12741274
// @public
12751275
export abstract class NgModuleRef<T> {
1276-
// @deprecated
1277-
abstract get componentFactoryResolver(): ComponentFactoryResolver;
12781276
abstract destroy(): void;
12791277
abstract get injector(): EnvironmentInjector;
12801278
abstract get instance(): T;

packages/core/src/application/application_ref.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@ import {EnvironmentInjector, type R3Injector} from '../di/r3_injector';
2828
import {INTERNAL_APPLICATION_ERROR_HANDLER} from '../error_handler';
2929
import {formatRuntimeError, RuntimeError, RuntimeErrorCode} from '../errors';
3030
import {Type} from '../interface/type';
31-
import {ComponentFactory, ComponentRef} from '../linker/component_factory';
32-
import {ComponentFactoryResolver} from '../linker/component_factory_resolver';
31+
import {ComponentRef} from '../linker/component_factory';
3332
import {NgModuleRef} from '../linker/ng_module_factory';
3433
import {ViewRef} from '../linker/view_ref';
3534
import {PendingTasksInternal} from '../pending_tasks_internal';
3635
import {RendererFactory2} from '../render/api';
3736
import {AfterRenderManager} from '../render3/after_render/manager';
38-
import {ComponentFactory as R3ComponentFactory} from '../render3/component_ref';
39-
import {isStandalone} from '../render3/def_getters';
37+
import {getComponentDef, isStandalone} from '../render3/def_getters';
4038
import type {Binding, DirectiveWithBindings} from '../render3/dynamic_bindings';
4139
import {ChangeDetectionMode, detectChangesInternal} from '../render3/instructions/change_detection';
4240
import {publishDefaultGlobalUtils as _publishDefaultGlobalUtils} from '../render3/util/global_utils';
@@ -46,6 +44,8 @@ import {TESTABILITY} from '../testability/testability';
4644
import {NgZone} from '../zone/ng_zone';
4745

4846
import {ProfilerEvent} from '../../primitives/devtools';
47+
import {ComponentFactory} from '../render3';
48+
import {stringifyCSSSelectorList} from '../render3/node_selector_matcher';
4949
import {profiler} from '../render3/profiler';
5050
import {isReactiveLViewConsumer} from '../render3/reactive_lview_consumer';
5151
import {EffectScheduler} from '../render3/reactivity/root_effect_scheduler';
@@ -87,10 +87,6 @@ export function publishSignalConfiguration(): void {
8787
});
8888
}
8989

90-
export function isBoundToModule<C>(cf: ComponentFactory<C>): boolean {
91-
return (cf as R3ComponentFactory<C>).isBoundToModule;
92-
}
93-
9490
/**
9591
* Provides additional options to the bootstrapping process.
9692
*
@@ -489,24 +485,24 @@ export class ApplicationRef {
489485
throw new RuntimeError(RuntimeErrorCode.ASYNC_INITIALIZERS_STILL_RUNNING, errorMessage);
490486
}
491487

492-
const resolver = this._injector.get(ComponentFactoryResolver);
493-
const componentFactory = resolver.resolveComponentFactory(component)!;
494-
this.componentTypes.push(componentFactory.componentType);
488+
const componentDef = getComponentDef(component)!;
489+
this.componentTypes.push(component);
495490

496491
// Create a factory associated with the current module if it's not bound to some other
497-
const ngModule = isBoundToModule(componentFactory)
498-
? undefined
499-
: this._injector.get(NgModuleRef);
492+
const ngModule = !componentDef.standalone ? undefined : this._injector.get(NgModuleRef);
500493
const {hostElement, directives, bindings} = normalizeBootstrapOptions(hostElementOrOptions);
501-
const selectorOrNode = hostElement || componentFactory.selector;
494+
const selectorOrNode = hostElement || stringifyCSSSelectorList(componentDef.selectors);
495+
496+
const componentFactory = new ComponentFactory<C>(componentDef);
502497
const compRef = componentFactory.create(
503498
injector,
504-
[],
499+
undefined,
505500
selectorOrNode,
506-
ngModule,
501+
ngModule?.injector || this._injector.get(EnvironmentInjector),
507502
directives,
508503
bindings,
509504
);
505+
510506
const nativeElement = compRef.location.nativeElement;
511507
const testability = compRef.injector.get(TESTABILITY, null);
512508
testability?.registerApplication(nativeElement);

packages/core/src/core_render3_private_export.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export {
1616
ProfilerEvent as ɵProfilerEvent,
1717
} from '../primitives/devtools';
1818
export {compileNgModuleFactory as ɵcompileNgModuleFactory} from './application/application_ngmodule_factory_compiler';
19-
export {isBoundToModule as ɵisBoundToModule} from './application/application_ref';
2019
export {injectChangeDetectorRef as ɵinjectChangeDetectorRef} from './change_detection/change_detector_ref';
2120
export {createInjector as ɵcreateInjector} from './di/create_injector';
2221
export {
@@ -281,10 +280,10 @@ export {compilePipe as ɵcompilePipe} from './render3/jit/pipe';
281280
export {isNgModule as ɵisNgModule} from './render3/jit/util';
282281
export {getAsyncClassMetadataFn as ɵgetAsyncClassMetadataFn} from './render3/metadata';
283282
export {
283+
ControlFlowBlock as ɵControlFlowBlock,
284284
ControlFlowBlockType as ɵControlFlowBlockType,
285285
DeferBlockData as ɵDeferBlockData,
286286
ForLoopBlockData as ɵForLoopBlockData,
287-
ControlFlowBlock as ɵControlFlowBlock,
288287
} from './render3/util/control_flow_types';
289288
export {
290289
FrameworkAgnosticGlobalUtils as ɵFrameworkAgnosticGlobalUtils,

packages/core/src/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export const enum RuntimeErrorCode {
131131
UNEXPECTED_ZONEJS_PRESENT_IN_ZONELESS_MODE = 914,
132132
MISSING_NG_MODULE_DEFINITION = 915,
133133
MISSING_DIRECTIVE_DEFINITION = 916,
134-
NO_COMPONENT_FACTORY_FOUND = 917,
134+
/* 917 - Removed */
135135
EXTERNAL_RESOURCE_LOADING_FAILED = 918,
136136
DEF_TYPE_UNDEFINED = -919,
137137
NG_MODULE_ID_NOT_FOUND = 920,

packages/core/src/linker.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export {
1515
ModuleWithComponentFactories,
1616
} from './linker/compiler';
1717
export {ComponentRef, ComponentFactory as ɵComponentFactory} from './linker/component_factory';
18-
export {ComponentFactoryResolver as ɵComponentFactoryResolver} from './linker/component_factory_resolver';
1918
export {DestroyRef} from './linker/destroy_ref';
2019
export {ElementRef} from './linker/element_ref';
2120
export {NgModuleFactory, NgModuleRef} from './linker/ng_module_factory';

packages/core/src/linker/component_factory_resolver.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.

packages/core/src/linker/ng_module_factory.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import {Injector} from '../di/injector';
1010
import {EnvironmentInjector} from '../di/r3_injector';
1111
import {Type} from '../interface/type';
1212

13-
import {ComponentFactoryResolver} from './component_factory_resolver';
14-
1513
/**
1614
* Represents an instance of an `NgModule` created by an `NgModuleFactory`.
1715
* Provides access to the `NgModule` instance and related objects.
@@ -24,18 +22,6 @@ export abstract class NgModuleRef<T> {
2422
*/
2523
abstract get injector(): EnvironmentInjector;
2624

27-
/**
28-
* The resolver that can retrieve component factories in a context of this module.
29-
*
30-
* Note: since v13, dynamic component creation via
31-
* [`ViewContainerRef.createComponent`](api/core/ViewContainerRef#createComponent)
32-
* does **not** require resolving component factory: component class can be used directly.
33-
*
34-
* @deprecated Angular no longer requires Component factories. Please use other APIs where
35-
* Component class can be used directly.
36-
*/
37-
abstract get componentFactoryResolver(): ComponentFactoryResolver;
38-
3925
/**
4026
* The `NgModule` instance.
4127
*/

packages/core/src/render3/component_ref.ts

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@ import {
2121
ComponentFactory as AbstractComponentFactory,
2222
ComponentRef as AbstractComponentRef,
2323
} from '../linker/component_factory';
24-
import {ComponentFactoryResolver as AbstractComponentFactoryResolver} from '../linker/component_factory_resolver';
2524
import {createElementRef, ElementRef} from '../linker/element_ref';
2625
import {NgModuleRef} from '../linker/ng_module_factory';
2726
import {RendererFactory2} from '../render/api';
2827
import {Sanitizer} from '../sanitization/sanitizer';
2928

30-
import {assertComponentType} from './assert';
3129
import {attachPatchData} from './context_discovery';
32-
import {getComponentDef, getDirectiveDef, getDirectiveDefOrThrow} from './def_getters';
30+
import {getDirectiveDef, getDirectiveDefOrThrow} from './def_getters';
3331
import {depsTracker} from './deps_tracker/deps_tracker';
3432
import {NodeInjector} from './di';
3533
import {reportUnknownPropertyError} from './instructions/element_validation';
@@ -62,50 +60,35 @@ import {
6260
} from './interfaces/view';
6361
import {MATH_ML_NAMESPACE, SVG_NAMESPACE} from './namespaces';
6462

63+
import {ProfilerEvent} from '../../primitives/devtools';
64+
import {TracingService} from '../application/tracing';
65+
import {DOCUMENT} from '../document';
6566
import {retrieveHydrationInfo} from '../hydration/utils';
67+
import {getComponentName} from '../internal/get_closest_component_name';
68+
import {NG_REFLECT_ATTRS_FLAG, NG_REFLECT_ATTRS_FLAG_DEFAULT} from '../ng_reflect';
6669
import {ChainedInjector} from './chained_injector';
6770
import {createElementNode, setupStaticAttributes} from './dom_node_manipulation';
71+
import {BINDING, Binding, BindingInternal, DirectiveWithBindings} from './dynamic_bindings';
72+
import {getDocument} from './interfaces/document';
6873
import {unregisterLView} from './interfaces/lview_tracking';
6974
import {Renderer} from './interfaces/renderer';
75+
import {SHARED_STYLES_HOST} from './interfaces/shared_styles_host';
7076
import {
7177
extractAttrsAndClassesFromSelector,
7278
stringifyCSSSelectorList,
7379
} from './node_selector_matcher';
7480
import {profiler} from './profiler';
75-
import {ProfilerEvent} from '../../primitives/devtools';
7681
import {executeContentQueries} from './queries/query_execution';
7782
import {enterView, leaveView} from './state';
7883
import {debugStringifyTypeForError, stringifyForError} from './util/stringify_utils';
7984
import {getComponentLViewByIndex, getTNode, storeLViewOnDestroy} from './util/view_utils';
85+
import {createLView, createTView, getInitialLViewFlagsFromDef} from './view/construction';
8086
import {directiveHostEndFirstCreatePass, directiveHostFirstCreatePass} from './view/elements';
8187
import {ViewRef} from './view_ref';
82-
import {createLView, createTView, getInitialLViewFlagsFromDef} from './view/construction';
83-
import {BINDING, Binding, BindingInternal, DirectiveWithBindings} from './dynamic_bindings';
84-
import {NG_REFLECT_ATTRS_FLAG, NG_REFLECT_ATTRS_FLAG_DEFAULT} from '../ng_reflect';
85-
import {TracingService} from '../application/tracing';
86-
import {getComponentName} from '../internal/get_closest_component_name';
87-
import {SHARED_STYLES_HOST} from './interfaces/shared_styles_host';
88-
import {DOCUMENT} from '../document';
89-
import {getDocument} from './interfaces/document';
9088

9189
const shadowRootSupported = typeof ShadowRoot !== 'undefined';
9290
const documentSupported = typeof Document !== 'undefined';
9391

94-
export class ComponentFactoryResolver extends AbstractComponentFactoryResolver {
95-
/**
96-
* @param ngModule The NgModuleRef to which all resolved factories are bound.
97-
*/
98-
constructor(private ngModule?: NgModuleRef<any>) {
99-
super();
100-
}
101-
102-
override resolveComponentFactory<T>(component: Type<T>): AbstractComponentFactory<T> {
103-
ngDevMode && assertComponentType(component);
104-
const componentDef = getComponentDef(component)!;
105-
return new ComponentFactory(componentDef, this.ngModule);
106-
}
107-
}
108-
10992
function toInputRefArray<T>(map: DirectiveDef<T>['inputs']): ComponentFactory<T>['inputs'] {
11093
return Object.keys(map).map((name) => {
11194
const [propName, flags, transform] = map[name];

packages/core/src/render3/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import {
4848
} from './util/discovery_utils';
4949

5050
export {NgModuleType} from '../metadata/ng_module_def';
51-
export {ComponentFactory, ComponentFactoryResolver, ComponentRef} from './component_ref';
51+
export {ComponentFactory, ComponentRef} from './component_ref';
5252
export {ɵɵgetInheritedFactory} from './di';
5353
export {getLocaleId, setLocaleId} from './i18n/i18n_locale_id';
5454
export {

0 commit comments

Comments
 (0)