Skip to content

Commit c3bb00a

Browse files
dylhunnthePunderWoman
authored andcommitted
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
1 parent bd9c2c5 commit c3bb00a

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_deferred/defer_deps_template.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const TestCmp_Defer_1_DepsFn = () => [import("./defer_deps_ext").then(m => m.CmpA), LocalDep];
1+
const $TestCmp_Defer_1_DepsFn$ = () => [import("./defer_deps_ext").then(m => m.CmpA), LocalDep];
22

33
function TestCmp_Defer_0_Template(rf, ctx) {
44
if (rf & 1) {
@@ -13,6 +13,6 @@ export class LocalDep {
1313

1414
function TestCmp_Template(rf, ctx) { if (rf & 1) {
1515
i0.ɵɵtemplate(0, TestCmp_Defer_0_Template, 2, 0);
16-
i0.ɵɵdefer(1, 0, TestCmp_Defer_1_DepsFn);
16+
i0.ɵɵdefer(1, 0, $TestCmp_Defer_1_DepsFn$);
1717
i0.ɵɵdeferOnIdle();
1818
} }

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_deferred/lazy_with_blocks_template.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const SimpleComponent_Defer_5_DepsFn = () => [MyLazyCmp];
1+
const $SimpleComponent_Defer_5_DepsFn$ = () => [MyLazyCmp];
22

33
function SimpleComponent_Defer_1_Template(rf, ctx) {
44
if (rf & 1) {
@@ -42,7 +42,7 @@ template: function SimpleComponent_Template(rf, ctx) {
4242
if (rf & 1) {
4343
i0.ɵɵtext(0);
4444
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);
45-
i0.ɵɵdefer(5, 1, SimpleComponent_Defer_5_DepsFn, 2, 3, 4);
45+
i0.ɵɵdefer(5, 1, $SimpleComponent_Defer_5_DepsFn$, 2, 3, 4);
4646
} if (rf & 2) {
4747
i0.ɵɵtextInterpolate1(" Visible: ", ctx.isVisible, ". ");
4848
i0.ɵɵadvance(5);

packages/compiler/src/template/pipeline/src/emit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ const phases: Phase[] = [
126126
{kind: Kind.Both, fn: expandSafeReads},
127127
{kind: Kind.Both, fn: generateTemporaryVariables},
128128
{kind: Kind.Tmpl, fn: allocateSlots},
129-
{kind: Kind.Tmpl, fn: createDeferDepsFns},
130129
{kind: Kind.Tmpl, fn: resolveI18nElementPlaceholders},
131130
{kind: Kind.Tmpl, fn: resolveI18nExpressionPlaceholders},
132131
{kind: Kind.Tmpl, fn: extractI18nMessages},
@@ -139,6 +138,7 @@ const phases: Phase[] = [
139138
{kind: Kind.Tmpl, fn: generateAdvance},
140139
{kind: Kind.Both, fn: optimizeVariables},
141140
{kind: Kind.Both, fn: nameFunctionsAndVariables},
141+
{kind: Kind.Tmpl, fn: createDeferDepsFns},
142142
{kind: Kind.Tmpl, fn: mergeNextContextExpressions},
143143
{kind: Kind.Tmpl, fn: generateNgContainerOps},
144144
{kind: Kind.Tmpl, fn: collapseEmptyInstructions},

packages/compiler/src/template/pipeline/src/phases/create_defer_deps_fns.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ export function createDeferDepsFns(job: ComponentCompilationJob): void {
4444
throw new Error(
4545
'AssertionError: slot must be assigned bfore extracting defer deps functions');
4646
}
47+
const fullPathName = unit.fnName?.replace(`_Template`, ``);
4748
op.resolverFn = job.pool.getSharedFunctionReference(
48-
depsFnExpr, `${job.componentName}_Defer_${op.handle.slot}_DepsFn`,
49+
depsFnExpr, `${fullPathName}_Defer_${op.handle.slot}_DepsFn`,
4950
/* Don't use unique names for TDB compatibility */ false);
5051
}
5152
}

0 commit comments

Comments
 (0)