Primeng: Maximum call stack size exceeded at ObjectUtils.equalsByValue

Created on 4 Jan 2019  路  25Comments  路  Source: primefaces/primeng

I'm submitting a ... (check one with "x")

[X] bug report => Search github for a similar issue or PR before submitting

Plunkr Case (Bug Reports)
I can't paste the code due client NDA

Current behavior
After primeng upgrade of our project to version 7.0.3 we got an internal error while editint p-tree nodes

`ERROR RangeError: Maximum call stack size exceeded
at Function.keys ()

at ObjectUtils.push(..(node_modules/primeng/components/utils/objectutils.js.ObjectUtils.equalsByValue (objectutils.js:20)

at ObjectUtils.push(..(node_modules/primeng/components/utils/objectutils.js.ObjectUtils.equalsByValue (objectutils.js:30)

at ObjectUtils.push(..(node_modules/primeng/components/utils/objectutils.js.ObjectUtils.equalsByValue (objectutils.js:55)

at ObjectUtils.push(..(node_modules/primeng/components/utils/objectutils.js.ObjectUtils.equalsByValue (objectutils.js:55)
`

We have not change any piece of code only primenNG upgrade and we get this primenNG internal error.

After seeking related issues I've just found #6977 was applied to primeNG 7.0.1, so it's must be related with the error.

Please tell us about your environment:
Debian 8.8 64 bits

  • Angular version: 7.1.3

  • PrimeNG version: 7.0.3

  • Browser:
    Chrome 71.0.3578.98
    Firefox 64
    Not tested on other

Most helpful comment

https://github.com/primefaces/primeng/commit/d2d4a294d05f0860a785b9dd65beb14dac9c2e63
Here you can see that visited got taken out, which acted as a cache. This was to safeguard against infinite loops.

All 25 comments

I also faced the same issue in primeng treetable. I raised in the Primeng forum please find the link below

https://forum.primefaces.org/viewtopic.php?f=35&t=57826&sid=183b0283bd590d26dfbf0e31974ded3f

but i didn't get any solutions

My environment is

Node: 10.14
Angular version: 7.1.2

PrimeNG version: 7.0.3

When I tried to update from Angular 6 to 7 and Primeng 6 to 7 I faced this issue.

Even I tried with PrimeNg version 7.0.4 and it has same error.

I am also experiencing this, but in p-table.

RangeError Maximum call stack size exceeded Function.push../node_modules/primeng/components/utils/objectutils.js.ObjectUtils.equalsByValue()@webpack:///node_modules/primeng/components/utils/objectutils.js:38:0 Array.isArray()@webpack:///node_modules/primeng/components/utils/objectutils.js:22:0 Object.prototype.hasOwnProperty.call()@webpack:///node_modules/primeng/components/utils/objectutils.js:47:0 Object.prototype.hasOwnProperty.call()@webpack:///node_modules/primeng/components/utils/objectutils.js:47:0 Array.isArray()@webpack:///node_modules/primeng/components/utils/objectutils.js:22:0 Object.prototype.hasOwnProperty.call()@webpack:///node_modules/primeng/components/utils/objectutils.js:47:0 Object.prototype.hasOwnProperty.call()@webpack:///node_modules/primeng/components/utils/objectutils.js:47:0 Array.isArray()@webpack:///node_modules/primeng/components/utils/objectutils.js:22:0 Object.prototype.hasOwnProperty.call()@webpack:///node_modules/primeng/components/utils/objectutils.js:47:0 UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36

https://github.com/primefaces/primeng/blob/2eee286dd973211d2c58d288bb62af598cee331b/src/app/components/utils/objectutils.ts#L22-L28

https://github.com/primefaces/primeng/blob/2eee286dd973211d2c58d288bb62af598cee331b/src/app/components/utils/objectutils.ts#L50-L54

Any object with a self-reference (direct or in an array) will infinite loop.

@cagataycivici , tagging you to get your attention. Sorry - but this is breaking.
Maybe switch over to lodash ( https://www.npmjs.com/package/lodash.isequal ). No reason to invent the wheel twice.

The following will infinite loop (I've exported the current method equalsbyValue locally):

const x = {} as any;
x.a = x;

const y = {} as any;
y.a = y;

this.equalsByValue(x, y);

Also

const x = {} as any;
x.a = [x];

const y = {} as any;
y.a = [y];

this.equalsByValue(x, y);

I couldn't replicate it. Could you provide stackblitz case?

https://stackblitz.com/github/primefaces/primeng-issue-template

@yigitfindikli , I've been trying to replicate this behavior without success. However, logging indicates that some of our users do experience it; I'm still investigating.

Fact remains that the equalsByValue method is a poor implementation of a deep equals, something that has been solved a long time ago. This will always result in bugs.

Hi, ran into the same issue. I believe the issue is caused by an object (o1) that has a reference to another object (o2) that references o1 again. Hence infinite recursion.

I think the issue is in ObjectUtils.equalsByValue. If you look at ObjectUtils.equalsByValue, you have:

for (i = length; i-- !== 0;)
if (!this.equalsByValue(obj1[i], obj2[i]))

In my case I have an object that references an array of objects. And each object in that array references the first object resulting in infinite recursion.

For me it fails on p-dropdown. version. 7.0.4

Hi, ran into the same issue. I believe the issue is caused by an object (o1) that has a reference to another object (o2) that references o1 again. Hence infinite recursion.

I think the issue is in ObjectUtils.equalsByValue. If you look at ObjectUtils.equalsByValue, you have:

for (i = length; i-- !== 0;)
if (!this.equalsByValue(obj1[i], obj2[i]))

In my case I have an object that references an array of objects. And each object in that array references the first object resulting in infinite recursion.

For me it fails on p-dropdown. version. 7.0.4

@cristitodoran
Could you provide stackblitz case?

https://stackblitz.com/github/primefaces/primeng-issue-template

It's very easy to get when not using dataKey. However, I'm getting this in my tables that do have dataKey specified, so I'm still investigating.

Easiest way to trigger: table with objects that self-reference, selectionMode specified, and no datakey: https://stackblitz.com/edit/github-s1mx7f

I'm just trying to emphasize that fixing the above scenario by checking for dataKey is not the way to approach this. It's not only p-table that is having problems, and all of this started happening after the equalsByValue refactor.

The equalsByValue's "refactor" needs ~refactoring~ fixing.

https://github.com/primefaces/primeng/commit/d2d4a294d05f0860a785b9dd65beb14dac9c2e63
Here you can see that visited got taken out, which acted as a cache. This was to safeguard against infinite loops.

Any update with this bug?

Same here. Two projects can not be upgraded to 7.0.X.
Is there a workaround? Or just waiting?

Any Update on this issue.

Same issue on 7.1.0.

How has this not been addressed yet?

This is occurring with our p-dropdown. Is this considered fixed?

This is occurring with our p-dropdown. Is this considered fixed?

Try using dataKey property in the meantime.
But no, it is not fixed, and there's no other word for what they're doing other than "ignoring".

That worked. Thank you Mysame.

This is occurring with our p-dropdown. Is this considered fixed?

Try using dataKey property in the meantime.
But no, it is not fixed, and there's no other word for what they're doing other than "ignoring".

How should this dataKey be used for p-dropdown? Please give more details! Thanks!

I've also experienced this behaviour once I've updated primeng to v 8.0.0.

Solutions:
-
-
- For table selection, DO NOT set [pSelectableRow] same as the whole row object:
Wrong:
<ng-template pTemplate="body" let-rowData let-columns="columns"> <tr [pSelectableRow]="rowData"> <td *ngFor="let col of columns"> {{rowData[col.field]}} </td> </tr> </ng-template>
Good:
<ng-template pTemplate="body" let-rowData let-columns="columns"> <tr [pSelectableRow]="rowData.uniqueObjectKey"> <td *ngFor="let col of columns"> {{rowData[col.field]}} </td> </tr> </ng-template>

Still getting this as of today. Embarassing.

Can you post some of your data in the dropdown?

I am also encountering the same issue with premeng's p-tree filter on mulitselect checkbox.. any solutions as of yet?

p-tree control setting selection and filter properties will cause stack overflow.
I occasionally see the print of selectOu in the console and find that it contains a lot of data. Is there a way to solve?

Unable to replicate with PrimeNG 9, if the issue persists please create a new ticket with a test case reproducing the issue e.g. stackblitz or a github repo and it will be reviewed by our team once again.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

watalberto picture watalberto  路  3Comments

jisqaqov picture jisqaqov  路  3Comments

markgoho picture markgoho  路  3Comments

Helayxa picture Helayxa  路  3Comments

Helayxa picture Helayxa  路  3Comments