Reduce re-renders to fix blinking line in Zoom&Highlight story#6315
Reduce re-renders to fix blinking line in Zoom&Highlight story#6315PavelVanecek merged 2 commits intomainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6315 +/- ##
==========================================
- Coverage 96.63% 96.61% -0.02%
==========================================
Files 221 221
Lines 20291 20329 +38
Branches 4157 4170 +13
==========================================
+ Hits 19608 19641 +33
- Misses 676 681 +5
Partials 7 7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Bundle ReportChanges will increase total bundle size by 1.17kB (0.05%) ⬆️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: recharts/bundle-cjsAssets Changed:
view changes for bundle: recharts/bundle-es6Assets Changed:
view changes for bundle: recharts/bundle-umdAssets Changed:
|
There was a problem hiding this comment.
Pull Request Overview
This PR focuses on performance optimization to reduce unnecessary re-renders in Recharts, specifically targeting the blinking line issue in the Zoom&Highlight story. The changes include adding React.memo to graphical components, optimizing axis selectors, and improving test infrastructure for performance testing.
- React.memo optimization for graphical components and axes
- Selector performance improvements with memoization
- Enhanced test infrastructure for stability testing
Reviewed Changes
Copilot reviewed 29 out of 29 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| storybook/stories/Examples/LineChart/LineChart.stories.tsx | Optimized story with useCallback for event handlers |
| src/cartesian/*.tsx | Added React.memo to Line, Area, Bar, Scatter, XAxis, YAxis components |
| src/state/selectors/axisSelectors.ts | Memoized XAxis and YAxis position selectors |
| test/**/*.spec.tsx | Added stability tests and updated test infrastructure |
| test/helper/* | Enhanced test utilities for performance and stability testing |
Comments suppressed due to low confidence (1)
src/cartesian/XAxis.tsx:1
- [nitpick] The variable
xAxisDefaultPropsshould be exported to maintain consistency with the similaryAxisDefaultPropsthat is exported in YAxis.tsx, or follow a consistent naming pattern for internal/external usage.
/**
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 29 out of 29 changed files in this pull request and generated no new comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Description
So the story in question https://main--63da8268a0da9970db6992aa.chromatic.com/iframe.html?globals=&args=&id=examples-linechart--highlight-and-zoom&viewMode=story was doing some pretty silly things:
So this helped a lot, but it's still doing some legit things like:
I fixed these by adding React.memo with basic comparator for graphical items, and custom comparator for axes (to catch the domain case). Plus tests.
Related Issue
Fixes #6307
Motivation and Context
Perf perf
Screenshots (if appropriate):
Before
Mouse hover renders YAxis labels:
https://github.com/user-attachments/assets/a7ff70c2-018a-4b5e-a73b-8ad6186f109d
Mouse click renders the whole thing (but nothing visually changes):
https://github.com/user-attachments/assets/c681e3f8-935d-4a49-8257-baf874d715d3
After
Mouse hover renders only cursor + tooltip + active dots (= only the components that visually change, can't get better than this):
https://github.com/user-attachments/assets/efa99aab-c481-4f92-98f2-8f293e85aaae
Mouse click renders some outer layers of the example (we could improve this further). The most interesting part - the line itself - no longer re-renders.
https://github.com/user-attachments/assets/6d3a435f-2d54-4193-8c78-23c81d0a19cc
Types of changes
Checklist: