emberjs / ember.js

Ember.js - A JavaScript framework for creating ambitious web applications
https://emberjs.com
MIT License
22.45k stars 4.21k forks source link

Converting circular structure to JSON #20446

Open imanny10 opened 1 year ago

imanny10 commented 1 year ago

I'm trying to add object( which has model) in storage . Getting this error TypeError: Converting circular structure to JSON --> starting at object with constructor 'Store' | property 'recordArrayManager' -> object with constructor 'RecordArrayManager' --- property 'store' closes the circle at JSON.stringify () at Storage.addFavorite (xy-chart-favs.js:43:1) at XYChartController.addXYFavourite (controller.js:573:1) at FavoritesStorage.addFavorite (favorites-storage.js:107:1)


     let favObj = {
      name: name,
      card: favorite,
      kpis: favorite.get('kpis').toArray(),
      fromDate: fromDate,
      toDate: toDate,
      isSVS: isSVS,
      siteId: siteId,
      plantId: plantId,
      unitId: unitId,
      aeicId: aeicId,
    };

    let cardObj = JSON.parse(JSON.stringify(favObj));
    const userFavorites = this._userObject(userId);
    userFavorites.favorites.addObject(cardObj);
 I'm deep cloning the object before pushing in storage array to avoid object reference which duplicates the nested object for new object.

 It was working in version 3.24 but after upgradation 4.8 (ember cli) not working
bmaehr commented 1 week ago

Same here :-(

NullVoxPopuli commented 1 week ago

Can you provide more information?

bmaehr commented 1 week ago

Sure. It is unfortunately not a trivial setup because of ember-data-fragments

ember-cli version: 4.8.0 ember-source version: 4.8.6 node version: v16.19.0 yarn version: 1.22.19 ember-data: 4.6.4 ember-data-model-fragments: 6.0.3

Error while processing route: tracking.index Converting circular structure to JSON
    --> starting at object with constructor 'Store'
    |     property 'recordArrayManager' -> object with constructor 'RecordArrayManager'
    --- property 'store' closes the circle TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Store'
    |     property 'recordArrayManager' -> object with constructor 'RecordArrayManager'
    --- property 'store' closes the circle
    at JSON.stringify (<anonymous>)
    at Class.persist (https://pubx.local/assets/vendor.js:227865:19)
    at Class.persist (https://pubx.local/assets/vendor.js:227363:33)
    at Proxy._updateStore (https://pubx.local/assets/vendor.js:226357:25)
    at Proxy.setUnknownProperty (https://pubx.local/assets/vendor.js:226346:14)
    at Proxy.superWrapper (https

The json looks like this

{
    "data": [
        {
            "id": "803aa7cbd1fa4fd4945457995d9bdfe1",
            "type": "userDetails",
            "links": {
                "self": "/jsonapi/userDetails/803aa7cbd1fa4fd4945457995d9bdfe1"
            },
            "attributes": {
                "active": true,
                "username": "me",
                "firstName": "m",
                "lastName": "e",
                "email": "me@example.com",
                "authorities": [
                    "ROLE_GLOBAL_ADMIN",
                    "ROLE_GLOBAL_LOGIN_FTP",
                    "ROLE_GLOBAL_LOGIN_WEB",
                    "ROLE_GLOBAL_LOGIN_WEBSERVICE",
                    "ROLE_GLOBAL_MB_MANAGER",
                    "ROLE_GLOBAL_REPORTING_MANAGER",
                    "ROLE_GLOBAL_SYSTEM_MANAGER",
                    "ROLE_GLOBAL_TRANSACION_MANAGER",
                    "ROLE_USER"
                ],
                "mbId": null,
                "mbName": null,
                "mbAuthorized": [],
                "mbCrmConnected": null
            }
        }
    ],
    "links": {
        "first": "/jsonapi/userDetails?page[number]=1&page[size]=10000",
        "last": "/jsonapi/userDetails?page[number]=1&page[size]=10000",
        "self": "/jsonapi/userDetails?reload=true"
    },
    "meta": {
        "totalResourceCount": 1
    }
}

The problem happens now while we started to migrate our big project from Ember 2.18 (there it is no problem) to a newer Ember

NullVoxPopuli commented 1 week ago

@runspired what's the migration off ember-data-fragments?

runspired commented 1 week ago

there is no migration path currently ready for 5.x: latest version we support it is 4.6 though we are nearing the release of 5.4 which will have support for a replacement paradigm we will then build a migration path to.

bmaehr commented 1 week ago

@runspired what's the migration off ember-data-fragments?

For us making the application work without fragments would be a rewrite of the whole application and we then would switch to an other framework.

there is no migration path currently ready for 5.x: latest version we support it is 4.6 though we are nearing the release of 5.4 which will have support for a replacement paradigm we will then build a migration path to.

You are talking about ember-data 5.4? Do you have any link to what is planed?

bmaehr commented 1 week ago

No improvement on ember-data: 4.6.6 ember-data-model-fragments: 6.0.10

bmaehr commented 1 week ago

Good news for me: The issue was cased by an old (4.2.2) version of ember-simple-auth

bmaehr commented 1 week ago

I have narrend it down. It happens, because we try to store an Ember model into the session of ember-simple-auth. It is ok to save an EmberObject there but not an Ember model.

Any idea how it is possible to "reduce" an EmberModel to an EmberObject?

runspired commented 2 days ago

you'd want to implement a toJSON method on the model, doesn't need to be an EmberObject (you probably don't want it to be an EmberObject)