Removing ViewRef causes error in Ivy
See original GitHub issueπ bug report
Affected Package
The issue is caused by package @angular/coreIs this a regression?
Yes, the previous version in which this bug was not present was: 8Description
I have a dropdown directive that creates a new view in a ViewContainerRef
of dropdowns host component. If that new view also has this directive it can create another view. In ngOnDestroy
of that directive I remove this view from ViewContainerRef
.
When parent dropdown is removed, I get an error in Ivy on destruction of nested directive created view.
Seems like destruction of first view causes destruction of the second view in sync and when I attempt to remove second view I get error, because length is already updated as if parent view is removed (length
is 1):
https://github.com/angular/angular/blob/0879d2e85d29c33c10e7314e49f5e4f0cc6ce2ba/packages/core/src/render3/view_engine_compatibility.ts#L209-L211
However both views are still there in indexOf
:
https://github.com/angular/angular/blob/0879d2e85d29c33c10e7314e49f5e4f0cc6ce2ba/packages/core/src/render3/view_engine_compatibility.ts#L299-L302
So nested view reports being at index of 1 and this assertion fails thinking there is only index of 0 because it thinks length
is 1:
https://github.com/angular/angular/blob/0879d2e85d29c33c10e7314e49f5e4f0cc6ce2ba/packages/core/src/render3/view_engine_compatibility.ts#L321-L331
π¬ Minimal Reproduction
Toggle parent, then toggle child, then toggle parent again to have them both removed https://stackblitz.com/edit/angular-ivy-viewref-bug
Hereβs working example on Angular 8 with ViewEngine: https://stackblitz.com/edit/angular-ve-viewref
π₯ Exception or Error
ERROR
Error: ASSERTION ERROR: index [Expected=> 1 < 1 <=Actual]
π Your Environment
Angular Version:
10.0.5
Issue Analytics
- State:
- Created 3 years ago
- Reactions:22
- Comments:7 (3 by maintainers)
Top GitHub Comments
I think removing function should be fine. Iβll look into it more later, @pkozlowski-opensource I will try to make a PR.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.