esnet / react-timeseries-charts

Declarative and modular timeseries charting components for React
http://software.es.net/react-timeseries-charts
Other
859 stars 283 forks source link

Can't pass null to Charts children #457

Open brandly opened 3 years ago

brandly commented 3 years ago

🐛Bug report

Describe the bug

I want to do this:

<Charts>
  {!hasDuplicateTimestamps && (
    <LineChart
      axis={key}
      series={series}
      columns={columns}
      style={style}
    />
  )}
  <ScatterChart
    axis={key}
    series={series}
    columns={columns}
    style={style}
  />
</Charts>

I might have multiple events at a given timestamp. If I do, I don't want to render a line.

Most places where children are looped over, nulls are checked:

https://github.com/esnet/react-timeseries-charts/blob/aa9c9b368100d78337b562d9e2833f2d90d9de3d/src/components/ChartRow.js#L312-L313

but there's no check here:

https://github.com/esnet/react-timeseries-charts/blob/aa9c9b368100d78337b562d9e2833f2d90d9de3d/src/components/ChartRow.js#L316-L317

resulting in this stack trace:

Uncaught (in promise) TypeError: Cannot read property 'props' of null
    at ChartRow.js:377
    at forEachSingleChild (react.development.js:1118)
    at traverseAllChildrenImpl (react.development.js:1007)
    ...

To Reproduce Steps to reproduce the behavior:

  1. Pass a null into the children for a <Charts> instance
  2. View crash

Expected behavior nulls are handle. I believe it's just a matter of adding if (chart === null) return; to line 317 of ChartRow.js


want me to send a PR?

f3rmat commented 3 years ago

Had this issue recently. One workaround is to use the visible prop.