fix(ivy): align NgModule registration timing with ViewEngine (#30244)
Currently in Ivy `NgModule` registration happens when the class is declared, however this is inconsistent with ViewEngine and requires extra generated code. These changes remove the generated code for `registerModuleFactory`, pass the id through to the `ngModuleDef` and do the module registration inside `NgModuleFactory.create`. This PR resolves FW-1285. PR Close #30244
This commit is contained in:

committed by
Alex Rickabaugh

parent
2f35dbfd3b
commit
f74373f2dd
@ -366,6 +366,9 @@ export function ɵɵdefineNgModule<T>(def: {
|
||||
|
||||
/** The set of schemas that declare elements to be allowed in the NgModule. */
|
||||
schemas?: SchemaMetadata[] | null;
|
||||
|
||||
/** Unique ID for the module that is used with `getModuleFactory`. */
|
||||
id?: string | null;
|
||||
}): never {
|
||||
const res: NgModuleDef<T> = {
|
||||
type: def.type,
|
||||
@ -375,6 +378,7 @@ export function ɵɵdefineNgModule<T>(def: {
|
||||
exports: def.exports || EMPTY_ARRAY,
|
||||
transitiveCompileScopes: null,
|
||||
schemas: def.schemas || null,
|
||||
id: def.id || null,
|
||||
};
|
||||
return res as never;
|
||||
}
|
||||
|
@ -9,7 +9,6 @@
|
||||
import {ɵɵdefineInjectable, ɵɵdefineInjector,} from '../../di/interface/defs';
|
||||
import {ɵɵinject} from '../../di/injector_compatibility';
|
||||
import * as r3 from '../index';
|
||||
import {registerNgModuleType} from '../../linker/ng_module_factory_loader';
|
||||
import * as sanitization from '../../sanitization/sanitization';
|
||||
|
||||
|
||||
@ -139,6 +138,4 @@ export const angularCoreEnv: {[name: string]: Function} = {
|
||||
'ɵɵsanitizeScript': sanitization.ɵɵsanitizeScript,
|
||||
'ɵɵsanitizeUrl': sanitization.ɵɵsanitizeUrl,
|
||||
'ɵɵsanitizeUrlOrResourceUrl': sanitization.ɵɵsanitizeUrlOrResourceUrl,
|
||||
|
||||
'ɵregisterNgModuleType': registerNgModuleType,
|
||||
};
|
||||
|
@ -11,7 +11,6 @@ import {resolveForwardRef} from '../../di/forward_ref';
|
||||
import {NG_INJECTOR_DEF} from '../../di/interface/defs';
|
||||
import {reflectDependencies} from '../../di/jit/util';
|
||||
import {Type} from '../../interface/type';
|
||||
import {registerNgModuleType} from '../../linker/ng_module_factory_loader';
|
||||
import {Component} from '../../metadata';
|
||||
import {ModuleWithProviders, NgModule, NgModuleDef, NgModuleTransitiveScopes} from '../../metadata/ng_module';
|
||||
import {flatten} from '../../util/array_utils';
|
||||
@ -117,14 +116,12 @@ export function compileNgModuleDefs(moduleType: NgModuleType, ngModule: NgModule
|
||||
.map(expandModuleWithProviders),
|
||||
emitInline: true,
|
||||
schemas: ngModule.schemas ? flatten(ngModule.schemas) : null,
|
||||
id: ngModule.id || null,
|
||||
});
|
||||
}
|
||||
return ngModuleDef;
|
||||
}
|
||||
});
|
||||
if (ngModule.id) {
|
||||
registerNgModuleType(ngModule.id, moduleType);
|
||||
}
|
||||
|
||||
let ngInjectorDef: any = null;
|
||||
Object.defineProperty(moduleType, NG_INJECTOR_DEF, {
|
||||
|
@ -14,9 +14,11 @@ import {R3Injector, createInjector} from '../di/r3_injector';
|
||||
import {Type} from '../interface/type';
|
||||
import {ComponentFactoryResolver as viewEngine_ComponentFactoryResolver} from '../linker/component_factory_resolver';
|
||||
import {InternalNgModuleRef, NgModuleFactory as viewEngine_NgModuleFactory, NgModuleRef as viewEngine_NgModuleRef} from '../linker/ng_module_factory';
|
||||
import {registerNgModuleType} from '../linker/ng_module_factory_registration';
|
||||
import {NgModuleDef} from '../metadata/ng_module';
|
||||
import {assertDefined} from '../util/assert';
|
||||
import {stringify} from '../util/stringify';
|
||||
|
||||
import {ComponentFactoryResolver} from './component_ref';
|
||||
import {getNgModuleDef} from './definition';
|
||||
import {maybeUnwrapFn} from './util/misc_utils';
|
||||
@ -87,6 +89,11 @@ export class NgModuleFactory<T> extends viewEngine_NgModuleFactory<T> {
|
||||
constructor(public moduleType: Type<T>) { super(); }
|
||||
|
||||
create(parentInjector: Injector|null): viewEngine_NgModuleRef<T> {
|
||||
return new NgModuleRef(this.moduleType, parentInjector);
|
||||
const moduleType = this.moduleType;
|
||||
const moduleRef = new NgModuleRef(moduleType, parentInjector);
|
||||
const ngModuleDef = getNgModuleDef(moduleType);
|
||||
ngModuleDef && ngModuleDef.id &&
|
||||
registerNgModuleType(ngModuleDef.id, moduleType as NgModuleType);
|
||||
return moduleRef;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user