ANovokmet / svelte-gantt

:calendar: Interactive JavaScript Gantt chart/resource booking component
https://anovokmet.github.io/svelte-gantt/
MIT License
507 stars 106 forks source link

TypeError: Cannot read properties of undefined (reading 'model') when updating rows and tasks #227

Open gubeils opened 2 months ago

gubeils commented 2 months ago

I am encountering an issue when updating the rows and tasks in svelte-gantt version "^4.3.2". I receive the following error:

TypeError: Cannot read properties of undefined (reading 'model')

image

Here is a screenshot of my rows and tasks data: image

I am using the method gantt.set({ rows, tasks }) to update the data.

ANovokmet commented 2 months ago

Any chance you could provide the error call stack?

gubeils commented 2 months ago

image

image

image

image

ANovokmet commented 2 months ago

Thank you. While I am fixing the issue, for an immediate fix, you can try checking if you are setting a task with a resourceId for a row that does not exist.

roman-yukhno-axon commented 1 month ago

Are there any updates? I faced the same problem. Tasks contain only existing resourceId.

UPD: I noticed that my tasks had two item with the same id. But the issue is still exists when I try to reset rows and tasks by passing empty arrays. It causes only when gantt had rows and tasks before

gantt.$set({ rows: [], tasks: [] });

image

UPD2: I don't know how it works, but resetting in this way works (when I reset tasks at first, and then reset rows in the queue, exactly in this sequence). And then I can fill it together again (again in the queue)

gantt.$set({ tasks: [] });
setTimeout(() => gantt.$set({ rows: [] }), 0);

setTimeout(() => gantt.$set({ rows, tasks }), 0);
ANovokmet commented 4 weeks ago

@roman-yukhno-axon I was testing this on v4.4.2 that was just released and it seems like using gantt.$set({ rows: [], tasks: [] }); does not cause any errors. Could you try again? Setting rows: [] when there are tasks still causes errors and I will work on this further.