Repository navigation
Breaking changes for 4.0 #6734
Replies: 6 comments 7 replies
|
Sounds good to me. Re: Cell The dedicated |
|
Another one: element cloning and prop injection? Multiple components accept ReactElement, and then clone it and add extra props. So your component is rendered as |
|
This will mean we're going to drop React16-17 support effectively. The extra complexity is not worth it I think. |
|
I am exploring how to integrate the new animations with other popular animation framework and AI came up with a good point so I am adding it here because it came up elsewhere already: Another 4.0 item from the animation work: better integration with external animation libraries, especially for shape-level wrappers. I spent some time exploring this on the current 3.9 animation preview branch and wired real website examples with:
I also considered GSAP, Motion One, and Popmotion. The conclusion was:
What already works todayThere are two distinct integration styles. 1. Let Recharts own the geometry, let another library own the timelineThis is what the new examples use. The external library drives a scalar progress value ( This works reasonably well for libraries that want to animate a number or spring value:
The best ergonomic version of this API would probably be a provider-level convenience prop, something like: <AnimationProgressProvider progress={progress}>
<LineChart ... />
</AnimationProgressProvider>instead of forcing users to write a Important point though: this is mostly an ergonomics improvement, not the main blocker. 2. Let the external library own the rendered SVG elementThis is the integration people usually expect from Motion / react-spring:
This is where the current API is still awkward. What the ideal integration would look likeFor users, the best version is something along these lines. Motion / react-spring as custom shapesfunction MotionBarShape(props: BarShapeProps) {
return <motion.path {...props} animate={{ opacity: 1 }} />;
}
<Bar shape={MotionBarShape} />or: const MotionRectangle = motion.create(Rectangle);
<Bar
shape={(props) => <MotionRectangle {...props} />}
/>or with react-spring: function SpringLineShape(props: CurveProps) {
const style = useSpring({ opacity: 1, from: { opacity: 0 } });
return <animated.path {...props} style={style} />;
}
<Line shape={SpringLineShape} />And for lower-level composition, ideally users could reuse Recharts geometry while swapping the rendered element/wrapper: <Rectangle as={motion.path} {...props} />
<Curve as={animated.path} {...props} />
<Sector as={motion.path} {...props} />That would be a very strong integration story for:
What is blocking this today1. Shape callbacks are invoked as plain functions, not rendered as React componentsThis is the biggest issue. Today shape functions go through shape = option(props, props.index)instead of: const ShapeComponent = option;
shape = <ShapeComponent {...props} />That means the API looks component-like, but it is not actually a real React component boundary. This causes several problems:
This is a very good 4.0 breaking-change candidate. Recommendation: in 4.0, treat function-valued 2. The hidden second argument should go awayRelated to the above: if we render shape functions as React components, we cannot keep this implicit second argument pattern. So the breaking change should be:
I did a quick search and I don't think we have many meaningful users of that second parameter. In practice This also fits nicely with the broader 4.0 cleanup theme already mentioned in this discussion: stop pretending something is a normal React element/component while secretly cloning/calling it with injected props. 3. Exported shape primitives are not designed for wrapper compositionIf we want this to feel first-class, the exported primitives should be composable with external wrappers:
Right now they are usable, but not optimized for:
For example,
Recommendation: make the low-level shape primitives friendlier to wrapper composition. That likely means one or both of:
4. Element-cloning APIs are still awkward for this use caseThis discussion already mentions another good 4.0 cleanup: stop taking a That matters here too. The wrapper-friendly API is much cleaner when users pass: <Bar shape={MyShape} />than when they pass: <Bar shape={<MyShape />} />and Recharts mutates it behind the scenes. For Motion / react-spring integration, the component form is the one we actually want. So I think this animation work is another strong argument for the 4.0 direction of:
What I would put on the 4.0 breaking-change listIf we want the best long-term integration with Motion / react-spring and similar libraries, I would propose: Breaking changes
Likely additive changes (not necessarily breaking, but highly desirable)
<AnimationProgressProvider progress={progress} />so external timeline libraries can drive Recharts without a bridge component.
Final recommendationIf the question is specifically:
then my answer is:
So I would treat this as a 4.0 item under the broader theme of:
That would unlock the cleanest integration story not just for Motion and react-spring, but also for anime.js, GSAP, Motion One, and similar libraries. |
Uh oh!
There was an error while loading. Please reload this page.
At this stage I'm throwing ideas around. We don't have a date for 4.0, this is brainstorming. Please share your thoughts and comments.
As I'm going through the codebase, some components and props are either pointless or blocking other things so I propose removing them from Recharts. This will be a breaking change so we will save it for 4.0.
Customized
Since 3.0, Customized component is pointless, one can just render whatever directly inside the chart. Remove without replacement.
CartesianAxis
I never understood why would anyone want to use CartesianAxis instead of XAxis/YAxis. I propose to move this component from public API to private API. It will still be there but we will have freedom to change the API without a major version bump.
Cell
Cell has two problems:
react-is. If we got rid of Cell then we can also get rid of react-is completely. (This part we could refactor around)Cell however is our way to pass props to individual components so we need something instead. We could either:
shapeprop, where one can provide a function. This function accepts all props and renders things. We could do stuff likeshape={(props) => <Rectangle {...props} fill={COLORS[props.index]} />}. Some of our components already have this, we need to make sure we have covered them all.WDYT?
All reactions