Skip to content

Calendar crashes when no data is present #246

@mdorr

Description

@mdorr

If no data is present (yet), the calendar component crashes with the following error:

Uncaught TypeError: Cannot read property 'value' of undefined
    at nivo-calendar.js:510
    at new WithPropsOnChange (withPropsOnChange.js:52)
   [...][1]

This causes an issue if p.e. the component is still waiting for data to be loaded asynchronously. The error is caused by in /packages/nivo-calendar/src/enhance.js:

if (domain === 'auto') {
  colorDomain = [minBy(data, 'value').value, maxBy(data, 'value').value]
}

If no data is given, minBy/maxBy will return undefined, and then .value is called on that. To prevent this from happening, _.get can be used, which will safely return undefined instead of throwing an error. I'll submit a pull request in a moment.

--
[1] Error message shortened for clarity. Full trace in attachment: nivo-calendar-error.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions