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

[charts] PieChart crashes on hover when changing data #12540

Closed
Rishi556 opened this issue Mar 22, 2024 · 5 comments · Fixed by #12571
Closed

[charts] PieChart crashes on hover when changing data #12540

Rishi556 opened this issue Mar 22, 2024 · 5 comments · Fixed by #12571
Labels
bug 🐛 Something doesn't work component: charts This is the name of the generic UI component, not the React module! good first issue Great for first contributions. Enable to learn the contribution process.

Comments

@Rishi556
Copy link
Contributor

Rishi556 commented Mar 22, 2024

Steps to reproduce

Link to live example: https://stackblitz.com/edit/mui-mui-x-jep8g4?file=src%2Fdemo.tsx

Steps:

  1. Use the left/right icon at the bottom to change chart.
  2. Immediately after clicking, move your mouse to the chart area to trigger a hover
  3. Chart Crashes
screen-capture.7.1.1.mp4

Current behavior

Piechart crashes.

Expected behavior

Chart should not crash, instead either show the tooltip for the section, or not show the tooltip and not crash.

Context

The pie chart displays data for different products, and only shows data for the product one at a time, depending on the selected product. This issue is reproducible on 4 browsers that have been tried(edge, chrome, firefox and safari).

Chrome dev tools complains about not being able to read color:

Uncaught TypeError: Cannot read properties of undefined (reading 'color')
    at DefaultChartsItemTooltipContent (chunk-BGQQ6PKH.js?v=630c7457:11503:44)
    at renderWithHooks (chunk-EL3PUDHE.js?v=630c7457:12171:26)
    at mountIndeterminateComponent (chunk-EL3PUDHE.js?v=630c7457:14921:21)
    at beginWork (chunk-EL3PUDHE.js?v=630c7457:15902:22)
    at HTMLUnknownElement.callCallback2 (chunk-EL3PUDHE.js?v=630c7457:3674:22)
    at Object.invokeGuardedCallbackDev (chunk-EL3PUDHE.js?v=630c7457:3699:24)
    at invokeGuardedCallback (chunk-EL3PUDHE.js?v=630c7457:3733:39)
    at beginWork$1 (chunk-EL3PUDHE.js?v=630c7457:19761:15)
    at performUnitOfWork (chunk-EL3PUDHE.js?v=630c7457:19194:20)
    at workLoopSync (chunk-EL3PUDHE.js?v=630c7457:19133:13)

I initially thought it was due to something with the animation, but was told my coworker, that even with skipAnimation the issue persists(but I haven't been able to recreate that myself).

Your environment

npx @mui/envinfo
  System:
    OS: Windows 11 10.0.22631
  Binaries:
    Node: 20.11.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.4.0 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.14.2 - ~\AppData\Roaming\npm\pnpm.CMD
  Browsers:
    Chrome: Not Found
    Edge: Chromium (122.0.2365.92)
  npmPackages:
    @emotion/react:  11.11.4
    @emotion/styled:  11.11.0
    @mui/base:  5.0.0-beta.40
    @mui/core-downloads-tracker:  5.15.14
    @mui/icons-material: ^5.15.14 => 5.15.14
    @mui/lab: 5.0.0-alpha.169 => 5.0.0-alpha.169
    @mui/material: ^5.15.14 => 5.15.14
    @mui/private-theming:  5.15.14
    @mui/styled-engine:  5.15.14
    @mui/styled-engine-sc: ^6.0.0-alpha.18 => 6.0.0-alpha.18
    @mui/system:  5.15.14
    @mui/types:  7.2.14
    @mui/utils:  5.15.14
    @mui/x-charts: ^v7.0.0 => 7.0.0
    @mui/x-data-grid: ^v7.0.0 => 7.0.0
    @mui/x-date-pickers: ^v7.0.0 => 7.0.0
    @mui/x-tree-view: ^7.0.0 => 7.0.0
    @types/react:  18.2.67
    react: ^18.2.0 => 18.2.0
    react-dom: ^18.2.0 => 18.2.0
    styled-components:  6.1.8
    typescript: ^5.4.3 => 5.4.3

Search keywords: pie charts hover

@Rishi556 Rishi556 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Mar 22, 2024
@zannager zannager added the component: charts This is the name of the generic UI component, not the React module! label Mar 25, 2024
@michelengelen michelengelen changed the title [Charts] PieChart crashes on hover when changing data [charts] PieChart crashes on hover when changing data Mar 26, 2024
@michelengelen
Copy link
Member

One easy fix could be this:

diff --git a/packages/x-charts/src/ChartsTooltip/DefaultChartsItemTooltipContent.tsx b/packages/x-charts/src/ChartsTooltip/DefaultChartsItemTooltipContent.tsx
index a2587dc0b..4cb677472 100644
--- a/packages/x-charts/src/ChartsTooltip/DefaultChartsItemTooltipContent.tsx
+++ b/packages/x-charts/src/ChartsTooltip/DefaultChartsItemTooltipContent.tsx
@@ -17,7 +17,7 @@ function DefaultChartsItemTooltipContent<T extends ChartSeriesType = ChartSeries
 ) {
   const { series, itemData, sx, classes } = props;

-  if (itemData.dataIndex === undefined) {
+  if (itemData.dataIndex === undefined || !series.data[itemData.dataIndex]) {
     return null;
   }
   const { displayedLabel, color } =

Would that be ok @alexfauquette ?

@michelengelen michelengelen added bug 🐛 Something doesn't work good first issue Great for first contributions. Enable to learn the contribution process. labels Mar 26, 2024
@alexfauquette
Copy link
Member

Yes, that proposal make sens 👍

@alexfauquette alexfauquette removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Mar 26, 2024
@Rishi556
Copy link
Contributor Author

Rishi556 commented Mar 26, 2024

I got to the same solution on my playground just a little while ago. Patching this into the actual codebase and seeing how it goes, thanks for the help!

Update: Looks like does fix it. Do you guys want me to make a PR?

Rishi556 added a commit to Rishi556/mui-x that referenced this issue Mar 26, 2024
mui#12540

Signed-off-by: Rishi556 <github@rishipanthee.com>
@alexfauquette
Copy link
Member

Yes, PR are welcome

Copy link

⚠️ This issue has been closed.
If you have a similar problem, please open a new issue and provide details about your specific problem.
If you can provide additional information related to this topic that could help future readers, please feel free to leave a comment.

How did we do @Rishi556?
Your experience with our support team matters to us. If you have a moment, please share your thoughts through our brief survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: charts This is the name of the generic UI component, not the React module! good first issue Great for first contributions. Enable to learn the contribution process.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants