angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

ng-options with track by and circular reference in objects -> Maximum call stack size exceeded

Open rasmusvhansen opened this issue 9 years ago • 5 comments

Observed in 1.4.8, but looking at the code, it seems to be an issue in 1.5 as well.

Reproduced here: http://jsfiddle.net/tn102eh8/2/ (1.4.8) And here: http://jsfiddle.net/tn102eh8/3/ (1.5.0-beta2) Related to #11372

The issue seems to be that ng-options runs equals(previousValue, nextValue) if trackby is used https://github.com/angular/angular.js/blob/master/src/ng/directive/ngOptions.js#L737

I think it should do

if (ngOptions.trackBy) {
    var prev = ngOptions.getTrackByValue(previousValue, ngOptions.trackBy);
    var next = ngOptions.getTrackByValue(nextValue, ngOptions.trackBy)
}

And then use angular.equals(prev, next) instead. I don't have an env. for angular development at the moment, but if you agree that this is an issue, I guess I can set it up and do a PR.

rasmusvhansen avatar Nov 25 '15 13:11 rasmusvhansen

We do have a test for circular references, but it doesn't use track by, so I think we can expect this to work. If you want to open a PR, we are happy to look at it.

Narretz avatar Nov 29 '15 17:11 Narretz

Any update on this?

studds avatar Apr 11 '16 17:04 studds

No, not yet. I'll take a look this week if nobody beats me to it. @studds if you want to open a PR with the change suggestion I'll be happy to look at it.

Narretz avatar Apr 11 '16 18:04 Narretz

Hi, what is the status of this issue? I found several issues dealing with the same problem, but none seems to be really closed. And indeed it seems that the problem still occurs in AngularJS 1.5.8.

BTW, I tried the fix suggested by rasmusvhansen and it works (and seems relevant).

Jimmy-Lopez avatar Aug 04 '16 06:08 Jimmy-Lopez

@Jimmy-Lopez No time yet. A PR with the proposed fix by you or anyone else wold definitely speed things up.

Narretz avatar Aug 09 '16 08:08 Narretz