react-chartjs-2 icon indicating copy to clipboard operation
react-chartjs-2 copied to clipboard

Data property gets mutated.

Open FilipAndersson245 opened this issue 8 years ago • 5 comments

When toggling datasets on and off repeatedly we sometimes get a crash. When using Redux the points array would be mutated and contain older data.

It seems like the copying is not enough in: https://github.com/jerairrest/react-chartjs-2/blob/master/src/index.js#L141 Its should probably copy the graph points in data array as well.

FilipAndersson245 avatar May 22 '18 12:05 FilipAndersson245

I'm not sure if you're seeing the same issue that we recently saw. However, we also saw a crash when we toggled datasets on and off. We found out that this was due to creating new datasets with the same dataset.data from previous datasets.

When we created datasets without changing the data array and then toggled the datasets, the crashes went away.

From what I've read, adding/removing points from the data array should also work, but I haven't tried it (our data array stays static for our app).

Hope this helps.

bdwade100 avatar Aug 25 '18 13:08 bdwade100

@FilipAndersson245 You're absolutely right! Proper solution would be to deep clone dataset not just do shallow copy with spread operator.

apieceofbart avatar Aug 31 '18 10:08 apieceofbart

Is there any plans to fix this? I wasn't expecting the library to mutate any data passed to it, so it took me a couple of hours to debug and understand what was going on.

rafaelbiten avatar Jun 18 '19 17:06 rafaelbiten

@FilipAndersson245 @bdwade100 @apieceofbart @rafaelbiten Hi. Would you please try the latest react-chartjs-2 version? Is this issue still there?

dangreen avatar Oct 26 '21 15:10 dangreen

Closed due to inactivity.

dangreen avatar Nov 01 '21 09:11 dangreen