Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line Graph - Cannot read from undefined property (reading 'x') when useMesh is enabled. #2630

Open
rob-cleeia opened this issue Aug 8, 2024 · 1 comment

Comments

@rob-cleeia
Copy link

rob-cleeia commented Aug 8, 2024

Describe/explain the bug
We're using Nivo/Line (responsive) to render some line graphs. The data we use is nondeterministic, so we validate the data before we send it to the graph. Based on the documentation (here: https://nivo.rocks/line/), we use the following type for line graph data:

interface line {
    id:   string | number;
    data: {
        x: number | string | Date
        y: number | string | Date
    }[]
}[]

However, we've recently noticed that if we have the x axis as a number and the y axis as a string, with useMesh enabled, it throws a client side exception.

To Reproduce
Render a Nivo/Line Graph with useMesh enabled, with data containing x axis as a number, and y axis as a string. EG:

import React from 'react';
import { ResponsiveLine } from '@nivo/line';

export const LineGraph: React.FC = () => (
  <div style={{ height: '20rem' }}>
    <ResponsiveLine
      data={[
        {
          id: '1',
          label: 'Joe Biden',
          data: [
            {
              x: 1973,
              y: 'Senator',
            },
            {
              x: 2009,
              y: 'Vice President',
            },
            {
              x: 2017,
              y: 'End of Vice Presidency',
            },
            {
              x: 2021,
              y: 'President',
            },
          ],
        },
      ]}
      useMesh
    />
  </div>
);
export default LineGraph;

Steps to reproduce the behaviour:

  1. Load above component.
  2. Hover mouse over Line Graph

Expected behaviour
Should not cause a client side error.

Screenshots
Chrome:
Screenshot 2024-08-08 at 12 00 12
FireFox:
Screenshot 2024-08-08 at 12 02 56

Desktop (please complete the following information - Not sure if this at all relevant, but okay):

  • OS: MacOS 14.5
  • Browser: Chrome v127.0.6533.73
  • Browser: FireFox v115.13.0esr (64-bit)

Additional context

  • We've disabled line-graphs on the website for now, as the data we receive is nondeterministic.
  • The error text in chrome is as follows:
    nivo-line.es.js:1 Uncaught TypeError: Cannot read properties of undefined (reading 'x')
        at nivo-line.es.js:1:1
        at renderWithHooks (react-dom.development.js:11121:1)
        at updateFunctionComponent (react-dom.development.js:16290:1)
        at beginWork$1 (react-dom.development.js:18472:1)
        at HTMLUnknownElement.callCallback (react-dom.development.js:20565:1)
        at Object.invokeGuardedCallbackImpl (react-dom.development.js:20614:1)
        at invokeGuardedCallback (react-dom.development.js:20689:1)
        at beginWork (react-dom.development.js:26949:1)
        at performUnitOfWork (react-dom.development.js:25748:1)
        at workLoopSync (react-dom.development.js:25464:1)
    
  • I asked this on Discord, and never got an answer.
    1. https://discord.com/channels/358204068931567619/358204068931567620/1271054826637365248
@plouc plouc mentioned this issue Oct 20, 2024
@CTX-Rachel
Copy link

I had the same problem, when temporarily removing LineChart everything was fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants