Skip to content

Commit

Permalink
refactor(compiler): Fix defer deps fn duplicate names in Template Pip…
Browse files Browse the repository at this point in the history
…eline (#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
  • Loading branch information
dylhunn authored and thePunderWoman committed Jan 25, 2024
1 parent 4507704 commit 4910133
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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();
} }
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/src/template/pipeline/src/emit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 4910133

Please sign in to comment.