Split Animate into JavascriptAnimate and CSSTransitionAnimate#6175
Split Animate into JavascriptAnimate and CSSTransitionAnimate#6175
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR splits the overloaded Animate component into two specialized variants: JavascriptAnimate for JavaScript-based animations and CSSTransitionAnimate for CSS transition-based animations. This separation provides clearer APIs for different animation types and fixes several animation bugs.
Key changes include:
- Creation of
JavascriptAnimateandCSSTransitionAnimatecomponents with focused responsibilities - Migration of chart components to use the appropriate animation variant
- Bug fixes for ErrorBar animations to properly scale in the correct direction
- Updated test suites reflecting the animation improvements
Reviewed Changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/animation/JavascriptAnimate.tsx |
New component for JavaScript-based animations with simplified API |
src/animation/CSSTransitionAnimate.tsx |
New component for CSS transition animations with style-based rendering |
src/cartesian/ErrorBar.tsx |
Updated to use CSSTransitionAnimate with correct directional scaling |
src/cartesian/Area.tsx |
Migrated from Animate to JavascriptAnimate |
src/cartesian/Bar.tsx |
Migrated from Animate to JavascriptAnimate |
src/cartesian/Line.tsx |
Migrated from Animate to JavascriptAnimate |
src/polar/Pie.tsx |
Migrated from Animate to JavascriptAnimate |
src/polar/Radar.tsx |
Migrated from Animate to JavascriptAnimate |
src/chart/Treemap.tsx |
Migrated from Animate to CSSTransitionAnimate |
| Test files | Updated to reflect new animation behavior and API changes |
Comments suppressed due to low confidence (1)
test/animation/Animate.timing.spec.tsx:106
- Using
it.fails()indicates this test is expected to fail. This suggests incomplete functionality or a known bug that should be addressed rather than marked as expected to fail.
it.fails('should call children function with current style', async () => {
| animation: boolean = true, | ||
| expectedStyles: { [key: string]: string } = {}, | ||
| ) { | ||
| function assertAnimationStyles(container: HTMLElement, animation: boolean, expectedStyles: { [key: string]: string }) { |
There was a problem hiding this comment.
The function signature changed to remove default parameter values which breaks backward compatibility. Consider keeping the original default parameters or adding overloads to maintain API compatibility.
| function assertAnimationStyles(container: HTMLElement, animation: boolean, expectedStyles: { [key: string]: string }) { | |
| function assertAnimationStyles( | |
| container: HTMLElement, | |
| animation: boolean = false, | |
| expectedStyles: { [key: string]: string } = {} | |
| ) { |
| Object.entries(expectedStyles).forEach(([key, value]) => { | ||
| expect(style).toContain(`${key}: ${value}`); | ||
| }); | ||
| if (animation === true) { |
There was a problem hiding this comment.
[nitpick] Using strict equality === true is unnecessary here since the parameter is already typed as boolean. Simply use if (animation) for better readability.
| if (animation === true) { | |
| if (animation) { |
| // @ts-expect-error types do not allow this | ||
| from="scaleY(0)" | ||
| // @ts-expect-error types do not allow this | ||
| to="scaleY{1}" |
There was a problem hiding this comment.
There's a syntax error in the to prop value. It should be "scaleY(1)" with parentheses, not "scaleY{1}" with curly braces.
| to="scaleY{1}" | |
| to="scaleY(1)" |
There was a problem hiding this comment.
Ah yes this is correct
There was a problem hiding this comment.
Also this is in the old spec which I will be deleting soon.
| } | ||
| onAnimationEnd(); | ||
| }; | ||
| }, [isActive, canBegin, duration, easing, begin, onAnimationStart, onAnimationEnd, animationManager, to]); |
There was a problem hiding this comment.
The useEffect dependency array includes to which could be a complex object that changes frequently, causing unnecessary re-renders. Consider using a ref or memoization for the to value if it's an object.
| }, [isActive, canBegin, duration, easing, begin, onAnimationStart, onAnimationEnd, animationManager, to]); | |
| }, [isActive, canBegin, duration, easing, begin, onAnimationStart, onAnimationEnd, animationManager, memoizedTo]); |
There was a problem hiding this comment.
Once I delete the old Animate I will change this type to string.
| data?: ReadonlyArray<TreemapDataType>; | ||
|
|
||
| /** | ||
| * @deprecated unused prop, doesn't do anything, use `key` instead |
There was a problem hiding this comment.
Adding a deprecation notice for animationId is good, but the component should also log a deprecation warning when this prop is used to help developers migrate away from it.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6175 +/- ##
==========================================
+ Coverage 96.53% 96.55% +0.01%
==========================================
Files 217 221 +4
Lines 19835 19938 +103
Branches 4087 4117 +30
==========================================
+ Hits 19148 19251 +103
Misses 681 681
Partials 6 6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Bundle ReportChanges will increase total bundle size by 9.85kB (0.41%) ⬆️. 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:
|
Description
The Animate component is overloaded, and mixes together JS animations and CSS animations with different capabilities. So let's split them!
I have replaced some of the usages but not all. I will work on the rest in separate PR.
The new variants also fix some bugs where animation was rendered with incorrect values for a single tick - compare the test suite to see, these were not visible in the browser.
It also fixes animation of ErrorBars, so now direction: y bars will scale in direction y, and direction x bars scale in direction x.
Before (look at the horizontal error bars)
Screen.Recording.2025-08-03.at.15.49.17.mov
After
Screen.Recording.2025-08-03.at.15.51.00.mov
Related Issue
#5768
Resolves #4055