refactor(compiler): Fix defer deps fn duplicate names in Template Pipeline (#54060)

Previously, defer deps fns names were only prefixed with the component name, meaning that distinct deps fns in the same component would produce a name collision. Now, we take into account the entire template function name when naming inner deps fns.

PR Close #54060
This commit is contained in:
Dylan Hunn 2024-01-24 14:25:49 -08:00 committed by Jessica Janiuk
parent bd9c2c5b3f
commit c3bb00a2eb
4 changed files with 7 additions and 6 deletions

View file

@ -1,4 +1,4 @@
const TestCmp_Defer_1_DepsFn = () => [import("./defer_deps_ext").then(m => m.CmpA), LocalDep];
const $TestCmp_Defer_1_DepsFn$ = () => [import("./defer_deps_ext").then(m => m.CmpA), LocalDep];
function TestCmp_Defer_0_Template(rf, ctx) {
if (rf & 1) {
@ -13,6 +13,6 @@ export class LocalDep {
function TestCmp_Template(rf, ctx) { if (rf & 1) {
i0.ɵɵtemplate(0, TestCmp_Defer_0_Template, 2, 0);
i0.ɵɵdefer(1, 0, TestCmp_Defer_1_DepsFn);
i0.ɵɵdefer(1, 0, $TestCmp_Defer_1_DepsFn$);
i0.ɵɵdeferOnIdle();
} }

View file

@ -1,4 +1,4 @@
const SimpleComponent_Defer_5_DepsFn = () => [MyLazyCmp];
const $SimpleComponent_Defer_5_DepsFn$ = () => [MyLazyCmp];
function SimpleComponent_Defer_1_Template(rf, ctx) {
if (rf & 1) {
@ -42,7 +42,7 @@ template: function SimpleComponent_Template(rf, ctx) {
if (rf & 1) {
i0.ɵɵtext(0);
i0.ɵɵtemplate(1, SimpleComponent_Defer_1_Template, 1, 0)(2, SimpleComponent_DeferLoading_2_Template, 1, 0)(3, SimpleComponent_DeferPlaceholder_3_Template, 1, 0)(4, SimpleComponent_DeferError_4_Template, 1, 0);
i0.ɵɵdefer(5, 1, SimpleComponent_Defer_5_DepsFn, 2, 3, 4);
i0.ɵɵdefer(5, 1, $SimpleComponent_Defer_5_DepsFn$, 2, 3, 4);
} if (rf & 2) {
i0.ɵɵtextInterpolate1(" Visible: ", ctx.isVisible, ". ");
i0.ɵɵadvance(5);

View file

@ -126,7 +126,6 @@ const phases: Phase[] = [
{kind: Kind.Both, fn: expandSafeReads},
{kind: Kind.Both, fn: generateTemporaryVariables},
{kind: Kind.Tmpl, fn: allocateSlots},
{kind: Kind.Tmpl, fn: createDeferDepsFns},
{kind: Kind.Tmpl, fn: resolveI18nElementPlaceholders},
{kind: Kind.Tmpl, fn: resolveI18nExpressionPlaceholders},
{kind: Kind.Tmpl, fn: extractI18nMessages},
@ -139,6 +138,7 @@ const phases: Phase[] = [
{kind: Kind.Tmpl, fn: generateAdvance},
{kind: Kind.Both, fn: optimizeVariables},
{kind: Kind.Both, fn: nameFunctionsAndVariables},
{kind: Kind.Tmpl, fn: createDeferDepsFns},
{kind: Kind.Tmpl, fn: mergeNextContextExpressions},
{kind: Kind.Tmpl, fn: generateNgContainerOps},
{kind: Kind.Tmpl, fn: collapseEmptyInstructions},

View file

@ -44,8 +44,9 @@ export function createDeferDepsFns(job: ComponentCompilationJob): void {
throw new Error(
'AssertionError: slot must be assigned bfore extracting defer deps functions');
}
const fullPathName = unit.fnName?.replace(`_Template`, ``);
op.resolverFn = job.pool.getSharedFunctionReference(
depsFnExpr, `${job.componentName}_Defer_${op.handle.slot}_DepsFn`,
depsFnExpr, `${fullPathName}_Defer_${op.handle.slot}_DepsFn`,
/* Don't use unique names for TDB compatibility */ false);
}
}