-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Tooltip rendering crashes when resizing the chart "Cannot read properties of undefined (reading 'payload')" #3981
Comments
Thanks for the fix. I can't reproduce at all, I wonder why its so random Edit: have retried the reproduction steps on different browsers multiple times and still can't reproduce |
@ckifer yeah it's really hard to reproduce, I'll keep looking for a way to reproduce it consistently But I still think that part of the code is smelly, |
makes sense |
<!--- Provide a general summary of your changes in the Title above --> ## Description Sometimes, the tooltip rendering would crash when the window has been resized > TypeError: Cannot read properties of undefined (reading 'payload') This is due to a mistake in `getItemByXY` in `generateCategoricalChart.tsx`. https://github.com/recharts/recharts/blob/0d5326a8cdcad34a3b9d7c0644abbb645ddffe87/src/chart/generateCategoricalChart.tsx#L2250-L2252 https://github.com/recharts/recharts/blob/7fb227dae542c3d3093506e6d80a2c2c366f9a26/src/util/ActiveShapeUtils.tsx#L142-L152 `isFunnel`, `isPie` and `isScatter` do not check if `activeItem` is defined, so it might cast it as a defined `FunnelItem`/`PieItem`/`ScatterItem` even if `activeItem` is undefined <!--- Describe your changes in detail --> I've added a nullcheck for activeItem ## Related Issue #3981 <!--- This project only accepts pull requests related to open issues --> <!--- If suggesting a new feature or change, please discuss it in an issue first --> <!--- If fixing a bug, there should be an issue describing it with steps to reproduce --> <!--- Please link to the issue here: --> ## Motivation and Context <!--- Why is this change required? What problem does it solve? --> This fixes a crash ## How Has This Been Tested? <!--- Please describe in detail how you tested your changes. --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> I manually checked that the crash doesn't happen anymore ## Screenshots (if appropriate): <img width="1040" alt="image" src="https://github.com/recharts/recharts/assets/8755930/9c5eaf0d-0bf4-486d-94fb-ae77b0ba8878"> ## Types of changes <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Checklist: <!--- Go over all the following points, and put an `x` in all the boxes that apply. --> <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [x] My code follows the code style of this project. - [x] My change requires a change to the documentation. - [x] I have updated the documentation accordingly. - [x] I have added tests to cover my changes. - [x] I have added a storybook story or extended an existing story to show my changes - [x] All new and existing tests passed.
A similar issue can be consistently reproduced in this sandbox. Hover your mouse over the chart and wait 3 seconds; an error will be thrown: 'Cannot read properties of undefined (reading 'payload')'. error is caused by the these are not ideal solutions since |
<!--- Provide a general summary of your changes in the Title above --> ## Description Sometimes, the tooltip rendering would crash when the window has been resized > TypeError: Cannot read properties of undefined (reading 'payload') This is due to a mistake in `getItemByXY` in `generateCategoricalChart.tsx`. https://github.com/recharts/recharts/blob/0d5326a8cdcad34a3b9d7c0644abbb645ddffe87/src/chart/generateCategoricalChart.tsx#L2250-L2252 https://github.com/recharts/recharts/blob/7fb227dae542c3d3093506e6d80a2c2c366f9a26/src/util/ActiveShapeUtils.tsx#L142-L152 `isFunnel`, `isPie` and `isScatter` do not check if `activeItem` is defined, so it might cast it as a defined `FunnelItem`/`PieItem`/`ScatterItem` even if `activeItem` is undefined <!--- Describe your changes in detail --> I've added a nullcheck for activeItem ## Related Issue recharts#3981 <!--- This project only accepts pull requests related to open issues --> <!--- If suggesting a new feature or change, please discuss it in an issue first --> <!--- If fixing a bug, there should be an issue describing it with steps to reproduce --> <!--- Please link to the issue here: --> ## Motivation and Context <!--- Why is this change required? What problem does it solve? --> This fixes a crash ## How Has This Been Tested? <!--- Please describe in detail how you tested your changes. --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> I manually checked that the crash doesn't happen anymore ## Screenshots (if appropriate): <img width="1040" alt="image" src="https://github.com/recharts/recharts/assets/8755930/9c5eaf0d-0bf4-486d-94fb-ae77b0ba8878"> ## Types of changes <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Checklist: <!--- Go over all the following points, and put an `x` in all the boxes that apply. --> <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [x] My code follows the code style of this project. - [x] My change requires a change to the documentation. - [x] I have updated the documentation accordingly. - [x] I have added tests to cover my changes. - [x] I have added a storybook story or extended an existing story to show my changes - [x] All new and existing tests passed.
fixed merged and released in 2.10.2 - please comment back if this persists |
Reproduction link
Steps to reproduce
The app crashes sometimes with "Cannot read properties of undefined (reading 'payload')" when the window is resized.
The crash is not consistent, so you should reload and try multiple times to reproduce
What is expected?
The tooltip should appear correctly
What is actually happening?
The whole app crashes (null pointer exception)
This is due to a mistake in
getItemByXY
ingenerateCategoricalChart.tsx
.recharts/src/chart/generateCategoricalChart.tsx
Lines 2250 to 2252 in 0d5326a
recharts/src/util/ActiveShapeUtils.tsx
Lines 142 to 152 in 7fb227d
isFunnel
,isPie
andisScatter
do not check ifactiveItem
is defined, so it might cast it as a definedFunnelItem
/PieItem
/ScatterItem
even ifactiveItem
is undefinedThe text was updated successfully, but these errors were encountered: