Issue with gantt.load(url, 'json') when Receiving Collections

I’m encountering a problem when I call gantt.load(url, 'json') from the server. Along with the tasks, I receive collections, which triggers an error:

less

Copy code

datastore.js:40 Uncaught TypeError: Cannot read properties of undefined (reading 'length')
    at ot._parseInner (datastore.js:40:29)
    at ot.parse (datastore.js:63:21)
    at t._process_loading (parsing.js:97:25)
    at t.on_load (parsing.js:63:8)
    at aa.<anonymous> (ajax_loading.js:22:9)
    at ajax.js:180:17

JSON response

{
    "tasks": [
        {
            "id": 29,
            "editable": true,
            "text": "Dummy Task 1",
            "description": null,
            "start_date": "24.10.2024.",
            "duration": 1,
            "progress": 0,
            "priority": "normal",
            "status": "waiting",
            "teams": [
                3,
            ],
            "external": [
                4
            ]
        },
        {
            "id": 28,
            "editable": true,
            "text": "Dummy Task 2",
            "description": null,
            "start_date": "24.10.2024.",
            "duration": 1,
            "progress": 0,
            "priority": "normal",
            "status": "waiting",
            "teams": [],
            "external": []
        },
        {
            "id": 11,
            "editable": true,
            "text": "Dummy Task 4",
            "description": "Sample description",
            "start_date": "24.10.2024.",
            "duration": 1,
            "progress": 0,
            "priority": "normal",
            "status": "waiting",
            "teams": [
                3
            ],
            "external": [
                3
            ]
        }
    ],
    "collections": {
        "teams": [
            {
                "value": 2,
                "label": "Team A"
            },
            {
                "value": 3,
                "label": "Team B"
            }
        ],
        "external": [
            {
                "value": 3,
                "label": "External Partner 1"
            },
            {
                "value": 4,
                "label": "External Partner 2"
            }
        ]
    }
}

When I remove the collections from the response, the error does not occur. However, this also results in the data not being displayed in the Gantt chart. I found a workaround by calling gantt.render(); after a delay of 500ms, but I’m concerned whether this will be a reliable solution in all cases.

Could anyone provide insights on why the presence of collections causes this error and if there’s a more stable solution to ensure the data displays correctly without relying on timeouts?

Hello Lazar,
Thank you for letting us know about that issue. It is reproduced with the parse method as well. And I was able to find that it is reproduced even if you have an empty collections array:
https://snippet.dhtmlx.com/4yn7zgvs

I will add it as a bug to our internal bug tracker. The dev team will fix the issue in the future, but I cannot give you any ETA.

It seems that the issue occurs because Gantt tries to find the links array. When it doesn’t find it in the root level of the data object, it tries to check it in the collections:
https://snippet.dhtmlx.com/4u5okudc

So, as a workaround, you can add an empty links array, then it will work as expected:
https://snippet.dhtmlx.com/oiw78h3c

https://snippet.dhtmlx.com/43yghlgv