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

fix: Line never checks for new totalLength on component update #3946

Merged
merged 2 commits into from Nov 9, 2023

Conversation

ckifer
Copy link
Member

@ckifer ckifer commented Nov 9, 2023

Description

getTotalLength only gets called on initial render in Line. When hiding and showing Line components in a specific chart the total length remains the same as it was before, when in fact it is now different (chart adjusts based on available space). In some cases this leads to the charts strokeDasharray not being correct and sometimes partially showing during animation. See videos

Related Issue

fixes #3359

Motivation and Context

Fix bug

How Has This Been Tested?

See videos

  • add storybook entry for toggling Line components via Legend click

Before

BeforeRecharts.mp4

After

After_Recharts.mp4

Screenshots (if appropriate):

Types of changes

  • 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:

  • 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
  • All new and existing tests passed.

@ckifer
Copy link
Member Author

ckifer commented Nov 9, 2023

@HHongSeungWoo

}

const totalLength = this.getTotalLength();
if (totalLength != null && totalLength !== this.state.totalLength) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part feels redundant. Since the null case does not exist and it's a primitive type, it seems fine to use this.setState({ totalLength: this.getTotalLength() });

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right because getTotalLength has a try catch and returns 0 if not found.

But there still is a case (often) where they are the same. I'd rather not call setState if they are.

I'll remove the null check

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tooltip inherits PureComponent, it already performs shallow comparisons.
Primitive type references always remain the same, so it won't rerender, but not calling it explicitly also seems good

@ckifer ckifer merged commit de36475 into recharts:master Nov 9, 2023
5 checks passed
@ckifer ckifer deleted the fix/lineAnimation branch November 9, 2023 16:59
GMer78 pushed a commit to GMer78/recharts-1 that referenced this pull request Nov 24, 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

Successfully merging this pull request may close these issues.

Animation of Line of Line chart in responsive container breaks after window resize with hide flag
4 participants