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

Tooltips aren't showing up if the top-level data prop is an empty array #3987

Closed
1 task done
charpeni opened this issue Nov 21, 2023 · 2 comments
Closed
1 task done

Comments

@charpeni
Copy link
Contributor

charpeni commented Nov 21, 2023

  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

Edit on CodeSandbox

Steps to reproduce

A regression was introduced in 2.9.3, where tooltips aren't showing up if the top-level data is an empty array.

See the reproduction link above.

The following works perfectly (meaning that tooltips are showing up) on 2.9.2, but stopped working starting from 2.9.3:

<ComposedChart data={[]}>
  [...]
  <Tooltip />
  <Bar data={pageData} dataKey="uv" />
</ComposedChart>

What is expected?

Edit on CodeSandbox

Screenshot 2023-11-21 at 1 53 07 PM

I would expect tooltips to appear even though the top-level data is empty, like it used to be the case previously.

What is actually happening?

See the reproduction link above.

Screenshot 2023-11-21 at 1 53 41 PM

When upgrading from 2.9.2 to 2.9.3 (or newer), tooltips aren't showing up anymore.

I investigated a little bit, and the reason is that payload contained within the tooltip is now an empty array and doesn't contain other data keys.

This is only happening with an empty array:

// Tooltips aren't showing up
<ComposedChart data={[]} />

// OK
<ComposedChart />
<ComposedChart data={['keep me']} />

As a workaround, we could omit data instead of passing an empty array, but in that case, it will be leading to another issue: #3985.

The only workaround remaining that should satisfy all usages would be to pass a non-empty array with some junk data, e.g., data={['keep me']}, but I would be really concerned that in the next version, we end up with that junk data somewhere else impacting our chart.

Environment Info
Recharts v2.10.1
React 18.2.0
System macOS Sonoma 14.0
Browser Chrome 119.0.6045.159
ckifer pushed a commit that referenced this issue Nov 27, 2023
<!--- Provide a general summary of your changes in the Title above -->

## Description

As dataEndIndex is -1 in an empty data array, it causes issues with
#3987.
It doesn't seem to be intentional

## Related Issue

#3987

## Motivation and Context

<!--- Why is this change required? What problem does it solve? -->

## 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. -->

## Screenshots (if appropriate):

## 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.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [ ] I have added tests to cover my changes.
- [ ] I have added a storybook story or extended an existing story to
show my changes
- [x] All new and existing tests passed.
@ckifer
Copy link
Member

ckifer commented Nov 27, 2023

should be fixed with #3988

will do a patch release at some point soon I think, thanks!

@ckifer
Copy link
Member

ckifer commented Nov 29, 2023

fixed in 2.10.2

@ckifer ckifer closed this as completed Nov 29, 2023
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