Apollo-client: Call Stack Exceeded Error in isEqual

Created on 16 May 2019  ยท  4Comments  ยท  Source: apollographql/apollo-client

๐Ÿ‘‹ Thanks for apollo, it's pretty cool

Intended outcome:

Data fetches without error

Actual outcome:

Call Stack Exceeded Error

Screen Shot 2019-05-16 at 10 59 01 AM

I did some digging into this error, and here is what I found:

isDifferentFromLastResult is called here:
https://github.com/apollographql/apollo-client/blob/master/packages/apollo-client/src/core/QueryManager.ts#L697

isEqual is called here:
https://github.com/apollographql/apollo-client/blob/master/packages/apollo-client/src/core/ObservableQuery.ts#L275

The two objects that are passed to isEqual look like this:

Screen Shot 2019-05-16 at 11 07 36 AM

a looks like:

image

b looks like:

image

When you invoke the getters on b it looks like a. Both b and a are infinitely nested:

a.allLinks[0].category.links[0] is the same object as a.allLinks[0]
b.allLinks[0].category.links[0] is the same object as b.allLinks[0]

The way isEqual is written, it does not support infinitely nested objects. This leads to the maximum call stack error because isEqual keeps calling itself with properties deeper and deeper into the infinitely nested tree.

Why is isEqual passed an infinitely nested tree? Is isEqual supposed to support infinitely nested trees?

How to reproduce the issue:

I'm not going to create a minimal reproduction quite yet, first I wanted to check and see if you had any insight based on the debugging above โ˜๏ธ

Versions

  System:
    OS: macOS 10.14.2
  Binaries:
    Node: 10.11.0 - /usr/local/bin/node
    Yarn: 1.15.2 - /usr/local/bin/yarn
    npm: 6.9.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 74.0.3729.131
    Firefox: 65.0
    Safari: 12.0.2

We are using @nuxtjs/[email protected] and [email protected], although I don't think the error comes from the nuxt integration. We also are using [email protected]

Any help or further guidance in debugging would be appreciated ๐Ÿ˜„

dependencies shipped โœ” confirmed ๐Ÿž bug ๐Ÿ™ƒ upstream

Most helpful comment

This should now be fixed if you update to [email protected], thanks to @capaj's PR #4915.

All 4 comments

Verified this issue is still present in [email protected]. Replacing the apollo implementation of isEqual with lodash isEqual fixes the error. Infinitely nested trees should definitely be supported.

This should now be fixed if you update to [email protected], thanks to @capaj's PR #4915.

Awesome, thanks @benjamn , @capaj !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sandervanhooft picture sandervanhooft  ยท  72Comments

msmfsd picture msmfsd  ยท  38Comments

alexmbp picture alexmbp  ยท  43Comments

tomitrescak picture tomitrescak  ยท  138Comments

dotansimha picture dotansimha  ยท  44Comments