feat(ivy): avoid unnecessary recompilations in TestBed (#29294)
Prior to this change, we always recompile all Components/Directives/Pipes even if they were AOT-compiled and had no overrides. This is causing problems in case we try to recompile a Component with "templateUrl" or "styleUrls" (which were already resolved in case of AOT) and generally this unnecessary work that TestBed was doing is not required. This commit adds extra logic to check whether a Component/Directive/Pipe already have compiled NG def (like ngComponentDef) and whether there are no overrides present - in this case recompilation is skipped. Recompilation is also skipped in case a Component/Directive has only Provider overrides - in this situation providers resolver function is patched to reflect overrides. Provider overrides are very common in g3, thus this code path ensures no full recompilation. PR Close #29294
This commit is contained in:

committed by
Matias Niemelä

parent
86aba1e8f3
commit
0244a2433e
@ -37,7 +37,7 @@ import {flushModuleScopingQueueAsMuchAsPossible, patchComponentDefWithScope, tra
|
||||
export function compileComponent(type: Type<any>, metadata: Component): void {
|
||||
let ngComponentDef: any = null;
|
||||
// Metadata may have resources which need to be resolved.
|
||||
maybeQueueResolutionOfComponentResources(metadata);
|
||||
maybeQueueResolutionOfComponentResources(type, metadata);
|
||||
Object.defineProperty(type, NG_COMPONENT_DEF, {
|
||||
get: () => {
|
||||
const compiler = getCompilerFacade();
|
||||
|
@ -357,6 +357,12 @@ export function patchComponentDefWithScope<C>(
|
||||
componentDef.pipeDefs = () =>
|
||||
Array.from(transitiveScopes.compilation.pipes).map(pipe => getPipeDef(pipe) !);
|
||||
componentDef.schemas = transitiveScopes.schemas;
|
||||
|
||||
// Since we avoid Components/Directives/Pipes recompiling in case there are no overrides, we
|
||||
// may face a problem where previously compiled defs available to a given Component/Directive
|
||||
// are cached in TView and may become stale (in case any of these defs gets recompiled). In
|
||||
// order to avoid this problem, we force fresh TView to be created.
|
||||
componentDef.template.ngPrivateData = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user