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.

Infinite loop in walkTNodeTree with nested *ngIf

See original GitHub issue

I’ve only just recently started using Angular (v7), so this might be my fault, but my experience tells me otherwise.

🐞 bug report

Affected Package

@angular/core 7.2.10

Description

<ng-container id="c1" *ngIf="b === 1">   <el *ngIf="a === 1"> <el *ngIf="a !== 1"> </ng-container>
<ng-container id="c2" *ngIf="b !== 1">   <el *ngIf="a === 1"> <el *ngIf="a !== 1"> </ng-container>

switching b from 1 to 2 while ‘a === 1’ causes infinite loop in walkTNodeTree (core/fesm2015/core.js:4777) and from the looks of it, it happens because upon walking “past” the first element in #c1, currentView[NEXT] is always null (since neither currentView nor NEXT change) and tnode.next is null because of the other condition (a).

However, if I move <el> outside of <ng-container> and replace their conditions with b === 1 && ... then everything works.

🔬 Minimal Reproduction

Couldn’t reproduce it on StackBlitz, so here is the whole repo of the project I’m working on: https://github.com/mrnateriver/angular-temporary-repo (sorry that it’s in russian, but you can just do ng serve, navigate to /login and click the yellow button on the right (“Далее”)).

The component in question is src/app/features/auth/login-form, and it is embedded in login-page.

🌍 Your Environment


Angular CLI: 7.3.6
Node: 10.15.3
OS: win32 x64
Angular: 7.2.10
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.13.6
@angular-devkit/build-angular     0.13.6
@angular-devkit/build-optimizer   0.13.6
@angular-devkit/build-webpack     0.13.6
@angular-devkit/core              7.3.6
@angular-devkit/schematics        7.3.6
@angular/cdk                      7.3.5
@angular/cli                      7.3.6
@angular/material                 7.3.5
@ngtools/webpack                  7.3.6
@schematics/angular               7.3.6
@schematics/update                0.13.6
rxjs                              6.3.3
typescript                        3.2.4
webpack                           4.29.0

Tested in Chrome 73.0.3683.86 and Firefox 66.0.2.

P.S.

Even if it’s not a bug but rather I’ve done something wrong, I still think that loop shouldn’t be infinite in any case.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ocombecommented, Apr 17, 2019

I tried your example and confirmed the issue. Then I tried it with the latest beta and everything seems to work fine. Here is the list of dependencies if you want to try:

"dependencies": {
    "@angular/animations": "8.0.0-beta.13",
    "@angular/cdk": "8.0.0-beta.2",
    "@angular/common": "8.0.0-beta.13",
    "@angular/compiler": "8.0.0-beta.13",
    "@angular/core": "8.0.0-beta.13",
    "@angular/forms": "8.0.0-beta.13",
    "@angular/material": "8.0.0-beta.2",
    "@angular/platform-browser": "8.0.0-beta.13",
    "@angular/platform-browser-dynamic": "8.0.0-beta.13",
    "@angular/router": "8.0.0-beta.13",
    "core-js": "^2.5.4",
    "hammerjs": "^2.0.8",
    "http-status-codes": "^1.3.2",
    "rxjs": "~6.3.3",
    "tslib": "^1.9.0",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "0.800.0-beta.15",
    "@angular/cli": "8.0.0-beta.15",
    "@angular/compiler-cli": "8.0.0-beta.13",
    "@angular/language-service": "8.0.0-beta.13",
    "@types/jasmine": "^3.3.9",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~3.3.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "3.4.3"
  }

I’ll close it since it works now, let me know if you still have an issue.

0reactions
angular-automatic-lock-bot[bot]commented, Sep 15, 2019

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

Angular Nested *ngFor is giving Infinite results on being used ...
This is causing an infinite loop. To fix this, you move the fetch languages logic as a serial operation ( switchMap ) on...
Read more >
Angulars NgIf, Else, Then - Explained - Ultimate Courses
NgIf is a behavioral directive that allows us to toggle part of a template based on a conditional value. This conditional would be...
Read more >
Angular Nested loops | ng-container for ngif & ngfor - YouTube
In this video you will learn how to work with ngFor and ngIf together and also what are the different errors which you...
Read more >
Package Diff: @angular/core @ 7.2.10 .. 7.2.11
n // If we do it in ProxyZone then we will get to infinite recursion. ... but we must keep the loop here...
Read more >
Angular ngIf: Complete Guide
Here we have nested the ngIf directives at the top of the component template so that we get all the data needed anywhere...
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