TypeError: Cannot read properties of undefined
See original GitHub issueI am getting the following errors:
TypeError: Cannot read properties of undefined (reading 'visible')
where the error references the following line and function:
_getSortedDatasetMetas(filterVisible) {
const me = this;
const metasets = me._sortedMetasets;
const result = [];
let i, ilen;
for (i = 0, ilen = metasets.length; i < ilen; ++i) {
const meta = metasets[i];
if (!filterVisible || meta.visible) { <---- THIS LINE
result.push(meta);
}
}
return result;
}
TypeError: Cannot read properties of undefined (reading 'controller')
where the error references the following line:
const style = meta.controller.getStyle(usePointStyle ? 0 : undefined);
The problem is that it happens randomly and I can not find any culprit for the problem.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:22
Top Results From Across the Web
Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError: Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >Uncaught TypeError: Cannot read property of undefined In
JavaScript TypeError is thrown when an operand or argument passed to a function is incompatible with the type expected by that operator or...
Read more >[Solved] Cannot read Properties of Undefined in JavaScript
The "Cannot read properties of undefined" error occurs when you try to access a property or a method on a variable that stores...
Read more >Uncaught TypeError : Cannot read properties of undefined
The solution to TypeError: Cannot read properties of undefined ... The root cause of the error is that the declared variable doesn't have...
Read more >Uncaught TypeError: Cannot read property 'value' of undefined
@TetraDev 'e' will return 'undefined' unless it's a valid TypeError. So you validate the TypeError in the 'if' statement and you can also ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is happening for me on
react-chartjs-2@3.3.0
withchart.js@3.6.0
.It seems that when the
data
prop passed into<Line>
changes, this can happen and has something to do with missingmetasets
in Chart.js/src/core/core.controller.js:_getSortedDatasetMetas:(note the
empty ⨉ 4
marker)I was able to mitigate by passing
redraw={true}
:<Line data={data} options={options} redraw />
But this means I lose out on the cool animation between old data and new data.
@dangreen This is a total guess, but could it be possible that the performance optimizations around here, something about the mutation of old datasets to produce new datasets, are what cause the
metasets
to be dropped on the Chart.js side? It seems like Chart.js 3.6.0 does use referential equality on datasets to perform some kind of optimization on their end.Thanks for this amazing package, hoping this can be a helpful pointer to the bug!
I had the same problem with
"chart.js": "3.6.2"
and"react-chartjs-2": "4.0.0"
, but only in Jest tests. The app was working fine, but the tests would fail with this:I found out that the issue is fixed if I move the
ChartJS.register()
call to be in the body component, and not outside of it, i.e.instead of