Skip to content

Commit 98376f2

Browse files
crisbetothePunderWoman
authored andcommitted
fix(compiler): changed after checked error in for loops (#52935)
Reworks the `repeater` instruction to go through `advance`, instead of passing in the index directly. This ensures that lifecycle hooks run at the right time and that we don't throw "changed after checked" errors when we shouldn't be. Fixes #52885. PR Close #52935
1 parent f5307bf commit 98376f2

21 files changed

Lines changed: 87 additions & 40 deletions

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_control_flow/basic_for_template.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function MyApp_Template(rf, ctx) {
1818
if (rf & 2) {
1919
$r3$.ɵɵadvance(1);
2020
$r3$.ɵɵtextInterpolate1(" ", ctx.message, " ");
21-
$r3$.ɵɵrepeater(2, ctx.items);
21+
$r3$.ɵɵadvance(1);
22+
$r3$.ɵɵrepeater(ctx.items);
2223
}
2324
}

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_control_flow/for_aliased_template_variables_template.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function MyApp_Template(rf, ctx) {
1919
if (rf & 2) {
2020
$r3$.ɵɵadvance(1);
2121
$r3$.ɵɵtextInterpolate1(" ", ctx.message, " ");
22-
$r3$.ɵɵrepeater(2, ctx.items);
22+
$r3$.ɵɵadvance(1);
23+
$r3$.ɵɵrepeater(ctx.items);
2324
}
2425
}

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_control_flow/for_data_slots_template.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ function MyApp_Template(rf, ctx) {
55
$r3$.ɵɵtemplate(4, MyApp_ng_template_4_Template, 0, 0, "ng-template");
66
}
77
if (rf & 2) {
8-
$r3$.ɵɵrepeater(1, ctx.items);
8+
$r3$.ɵɵadvance(1);
9+
$r3$.ɵɵrepeater(ctx.items);
910
}
1011
}

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_control_flow/for_impure_track_reuse_template.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ function MyApp_Template(rf, ctx) {
88
$r3$.ɵɵrepeaterCreate(2, MyApp_For_3_Template, 1, 1, null, null, $_forTrack0$, true);
99
}
1010
if (rf & 2) {
11-
$r3$.ɵɵrepeater(0, ctx.items);
12-
$r3$.ɵɵrepeater(2, ctx.otherItems);
11+
$r3$.ɵɵrepeater(ctx.items);
12+
$r3$.ɵɵadvance(2);
13+
$r3$.ɵɵrepeater(ctx.otherItems);
1314
}
1415
}

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_control_flow/for_pure_track_reuse_template.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ function MyApp_Template(rf, ctx) {
66
$r3$.ɵɵrepeaterCreate(2, MyApp_For_3_Template, 1, 1, null, null, $_forTrack0$);
77
}
88
if (rf & 2) {
9-
$r3$.ɵɵrepeater(0, ctx.items);
10-
$r3$.ɵɵrepeater(2, ctx.otherItems);
9+
$r3$.ɵɵrepeater(ctx.items);
10+
$r3$.ɵɵadvance(2);
11+
$r3$.ɵɵrepeater(ctx.otherItems);
1112
}
1213
}

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_control_flow/for_template_variables_listener_template.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function MyApp_Template(rf, ctx) {
2323
if (rf & 2) {
2424
$r3$.ɵɵadvance(1);
2525
$r3$.ɵɵtextInterpolate1(" ", ctx.message, " ");
26-
$r3$.ɵɵrepeater(2, ctx.items);
26+
$r3$.ɵɵadvance(1);
27+
$r3$.ɵɵrepeater(ctx.items);
2728
}
2829
}

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_control_flow/for_template_variables_scope_template.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ function MyApp_Template(rf, ctx) {
1717
}
1818
if (rf & 2) {
1919
$r3$.ɵɵtextInterpolate4(" ", ctx.$index, " ", ctx.$count, " ", ctx.$first, " ", ctx.$last, " ");
20-
$r3$.ɵɵrepeater(1, ctx.items);
21-
$r3$.ɵɵadvance(3);
20+
$r3$.ɵɵadvance(1);
21+
$r3$.ɵɵrepeater(ctx.items);
22+
$r3$.ɵɵadvance(2);
2223
$r3$.ɵɵtextInterpolate4(" ", ctx.$index, " ", ctx.$count, " ", ctx.$first, " ", ctx.$last, " ");
2324
}
2425
}

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_control_flow/for_template_variables_template.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function MyApp_Template(rf, ctx) {
1919
if (rf & 2) {
2020
$r3$.ɵɵadvance(1);
2121
$r3$.ɵɵtextInterpolate1(" ", ctx.message, " ");
22-
$r3$.ɵɵrepeater(2, ctx.items);
22+
$r3$.ɵɵadvance(1);
23+
$r3$.ɵɵrepeater(ctx.items);
2324
}
2425
}

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_control_flow/for_track_by_field_template.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function MyApp_Template(rf, ctx) {
1919
if (rf & 2) {
2020
$r3$.ɵɵadvance(1);
2121
$r3$.ɵɵtextInterpolate1(" ", ctx.message, " ");
22-
$r3$.ɵɵrepeater(2, ctx.items);
22+
$r3$.ɵɵadvance(1);
23+
$r3$.ɵɵrepeater(ctx.items);
2324
}
2425
}

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_control_flow/for_track_by_index_template.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function MyApp_Template(rf, ctx) {
1818
if (rf & 2) {
1919
$r3$.ɵɵadvance(1);
2020
$r3$.ɵɵtextInterpolate1(" ", ctx.message, " ");
21-
$r3$.ɵɵrepeater(2, ctx.items);
21+
$r3$.ɵɵadvance(1);
22+
$r3$.ɵɵrepeater(ctx.items);
2223
}
2324
}

0 commit comments

Comments
 (0)