Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RangeError: Maximum call stack size exceeded #3

Closed
alexhtech opened this issue Aug 9, 2017 · 10 comments
Closed

RangeError: Maximum call stack size exceeded #3

alexhtech opened this issue Aug 9, 2017 · 10 comments

Comments

@alexhtech
Copy link

Hi!

const json = require('./test.json')
const Jsona = require('Jsona').default

const dataFormatter = new Jsona()

console.log(JSON.stringify(dataFormatter.deserialize(json)))

test.json.txt

I'm getting error when my api service respond to me this json that includes object with block_translations, if I remove it from json all is works fine. Where is error ? In test.json or?

@olosegres
Copy link
Owner

@aleksdp Hi, you have circular relationship (translations[0] has link to root sections entity).
Jsona has not been support support such relationships.

It fixed in version 1.0.12, update please.

@alexhtech
Copy link
Author

@olosegres Thanks! You are doing great things!:)

@alexhtech
Copy link
Author

console.log(JSON.stringify(dataFormatter.deserialize(json)))
^

TypeError: Converting circular structure to JSON

Now Object couldn't be stringified with JSON.stringify()

@alexhtech alexhtech reopened this Aug 10, 2017
@olosegres
Copy link
Owner

Your code calls JSON.stringify, try to log deserialized data without stringifying

@olosegres
Copy link
Owner

@aleksdp I cant imagine case when you have to use stringifying this data in project code

@alexhtech
Copy link
Author

@olosegres So simple. I use React+Redux for server render and I need to gather together whole my redux store and serialize it to string and send to client side

@alexhtech
Copy link
Author

@olosegres I know that I can keep jsonapi data in redux as is and then use dataformatter for data visuilization, but it don't approach for me

@olosegres
Copy link
Owner

olosegres commented Aug 10, 2017

@aleksdp The logic inherent in the construction of simplified objects assumes the creation of circular structures from recursive JSON API relationships (I can't imagine more logical implementation for such situations, if you have ideas - tell me).

You may just delete unneeded circular relation from deserialized object :)

Or you may pay attention to other ways to dehydrate & rehydrate store state with JSON API & Jsona data:

  1. In fluxible project I use special methods to dehydrate & rehydrate Jsona models. Jsona.serialize on dehydration (back to JSON API format) and Jsona.deserialize on clientside store rehydration (again to Jsona models).
    But it using 0.2.x version of Jsona, where possible serialization with all included relationships automatically.
    Now, in 1.0.x version, you need to pass includeNames array with names of relations that should be added to included part of JSON (if you need automatic serialization of all relations, I can return it).

  2. In redux project I keep all JSON API entities normalized in store in special format, so-called reduxObject - result object of json-api-normalizer. The result is a repository of JSON API entities from all requests. And only when I need certain entity or collection I use Jsona's denormalizeReduxObject method, that creates simplified objects from stored data like deserialize from JSON (usually denormalization placed in store connectors and action creators).

@olosegres
Copy link
Owner

@aleksdp Hi!
Have you resolve the problem?

@alexhtech
Copy link
Author

@olosegres I with my team decided turn off server side rendering, so I'm not getting this error, I think we can close this bug because this problem is obvious. For the future I think I will make reducer to store data as it is and I will transform data with help jsona only in data view component, it must decide this trouble :) thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants