question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Removing ViewRef causes error in Ivy

See original GitHub issue

🐞 bug report

Affected Package

The issue is caused by package @angular/core

Is this a regression?

Yes, the previous version in which this bug was not present was: 8

Description

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:closed
  • Created 3 years ago
  • Reactions:22
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
waterpleacommented, Jul 27, 2020

I think removing function should be fine. I’ll look into it more later, @pkozlowski-opensource I will try to make a PR.

0reactions
angular-automatic-lock-bot[bot]commented, Sep 13, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ViewContainerRef - Angular
Returns. ViewRef | null : The ViewRef instance, or null if the index is out of range. ... If not specified, the last...
Read more >
angular 13 ng build library fails (ivy partial compilation mode)
I try ng build my-lib and get the below error. βœ– Compiling with Angular sources in Ivy partial compilation mode. Transform failed withΒ ......
Read more >
TensorFlow v2.0.0-beta0 Release - GitClear
fix(ivy): ViewRef. ... test(ivy): add root cause for failing forms e2e tests ... Remove duplicated model class definitions in `test/cases/base_test.rb`.
Read more >
@angular/tsc-wrapped | Yarn - Package Manager
Angular compiler option enableIvy has been removed as Ivy is the only rendering ... with headers set will need to remove the headers...
Read more >
Guide Leading Up to Angular 9.0.0 Release - HUSPI
ivy : component emitted correctly when it's removed from its module ... avoid error due to circular dependency in EsmDependencyHostΒ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found