-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead. at {Component} #3615
Comments
Thanks, noted! Unfortunately moving away from defaultProps causes unintended bugs due to the way recharts works. But this is known and we're trying to get away from them where we can. Edit: see solution in 2.x #3615 (comment) |
FYI this also happens for the Tooltip component |
Reference for why this is an issue #3438 (comment) |
@akamfoad all of our functional refactors are going to have this issue. We may have to prepared to handle soon as I'm going to release 2.7. Let me know if you have any thoughts |
@ckifer But I think the sooner we embrace JS default params the better, I see many teams are going in this direction, especially those who use TypeScript, I see that is quite the default practice. This is not going to break semver if we do it in v2, because we just change how we receive the default values, internally, for the users of the library everything will be the same and the warning goes away. What do you think? |
@akamfoad I totally agree, but we still have the cloneElement issue linked above (#3438 (comment)). I believe all of the components we have refactored besides Tooltip are safe from that issue so we should be able to move them over |
I believe this list holds those that we cannot touch without fear of breaking things |
So only those components will cause issue if defaultProps is removed, that another component/function needs to access them, including I'm guessing there is a lot of them, especially those from the list in Which means they in fact cause breaking change, when migrated to default params. So we might need to hold off here and revert the Tooltip refactor, that is an easy one. The warning is shown only for Functional Components with defaultProps, but the default behavior may changes in the future for how this affects components (if I understood the RFC correctly). Which means, its probably for the best to prepare for v3. |
Btw @ckifer I think its probably for the best, this might encourage us to have major version (not very soon tho), where we internally do not rely on defaultProps, or cloneElement, instead we use normal JS default params, and renderProps (which is not my personal favorite), or Context API. This way, the children can both render and subscribe to context's provided by the charts (or a an HoC) parent and render, clutter-free |
Thanks for the thoughts @akamfoad! Yeah I agree - I've been shying away from 3.x because it's a lot of work and there's a lot of breaking changes we need to merge in and document but there hasn't really been any meaningful progress made towards it. But yes we definitely need to 100% rid ourselves of the cloneElement approach, it's the cause of a lot of issues (but it's also some of the magic of recharts which is why it's tough to remove or at least tough to test once you remove it). |
No solution yet but we're aware of it, thanks |
I also need the solution asap, do your job devs. |
There are no devs that work on this project as a job. Please feel free to contribute. |
Just leaving this here: const error = console.error;
console.error = (...args: any) => {
if (/defaultProps/.test(args[0])) return;
error(...args);
}; |
Hi, is this a temporary fix that we can implement for now? |
@ooanishoo This will just hide the warning, but there's not really anything else you can do until it's fixed upstream anyway. |
Having the same issue. Is there an update on where this might be fixed? |
I was just about to ask a question, but I guess I won't. Everyone knows 🤣 |
No update really besides some noodling in my head to try to pick a path forwards. If I work on anything at all next it will be this, I just can't make time for it right now as other (life) priorities prevail. |
Risky elements are defined (by me at least 😅 ) as any that are referenced by a call to
All other components outside of these should be able to be refactored to use default params with relative certainty they won't break things. This makes this issue actionable and means that If anyone wants to take the changes or the change for one component let me know. |
Text refactored in #3670. Curve is open for contribution as well as any others that may currently have issue |
Thanks for working on this you guys. Patiently waiting for the eventual fix 🙏 |
@ckifer just wanted to let you know I didn't forget last weekend, I crashed my bicycle (whoops) so wasn't in much of a space to bang it out. I'll have time this weekend to have a look :) |
@ckifer Just been going through this this morning and noticed it seems as though we have an With all that being said, would a sufficient solution be to update the context or hooks to implement a default props of some sorts? I have had a go at implementing a solution but I think I most likely need a bit of a more detailed mental modal of how the overall parts are playing together as my initial attempt killed the unit tests 👀 |
That's correct. The problem is that there are parts of code that read
defaultProps directly from DOM, by searching the element tree and then
matching displayName.
Once those are removed, and the context and hooks is the way to do that,
the warning will go away.
…On Mon, May 6, 2024, 13:37 Paul Singh ***@***.***> wrote:
@ckifer <https://github.com/ckifer> Just been going through this this
morning and noticed it seems as though we have an XAxisContext which is
responsible for generating a prop map which is fed to useXAxisOrThrow --
from my understanding this hook is returning the current props for the axis
to the XAxis component and the returned value is being fed to the
CatesianGrid component.
With all that being said, would a sufficient solution be to update the
context or hooks to implement a default props of some sorts? I have had a
go at implementing a solution but I think I most likely need a bit of a
more detailed mental modal of how the overall parts are playing together as
my initial attempt killed the unit tests 👀
—
Reply to this email directly, view it on GitHub
<#3615 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIMTCUWW65FOKZ73EJA2VDZA4CG3AVCNFSM6AAAAAAY6DGBPOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJVGE4DIMZXGQ>
.
You are receiving this because you were assigned.Message ID:
***@***.***>
|
+1, its basically all going to lead back to untangling We need to make the connection between reference elements and axis elements in a different way (context and hooks) |
Thanks for keeping us posted for the progress @ckifer ! Really appreciate it! I found this thread when testing react 19 beta. Looks like this starts to cause runtime issues in React 19 since |
Sure thing! Right, this is why the warning is logged. We won't be able to support React 19 until we finish this. Although in 2.x branch we might accept #4542 as version 2.12.8 which would move these components back to classes to get rid of the errors. We could then add react 19 to peerDeps and keep working on 3.x without blocking people from upgrading. |
Could this be taken care of (atleast while waiting for next version) by using a wrapper function, that would get the defaultValues from DOM and either pass props or if they are missing then the defaultValues to the real component?
or did I totally misunderstand the problem... |
@jukkahuuskonen I guess when we say dom here we're talking about from react elements, or the virtual dom. The linked PR wraps our current functions in class components which solves the issue. I think that the path forward while waiting |
Thanks for your work @ckifer ! Will be waiting for your great updates! |
@ckifer Thank you for your efforts! |
Removing defaultProps do not make any sense by the React team. So I think that you should one an issue on the React repository. |
defaultProps will stay on class components. This warning is about defaultProps on functional components. So we could technically solve this by rewriting everything from functional components to classes. But that also means rewriting all hooks. |
That does not make any sense. Using classes is going back in time, and it is an old pattern. We can have functions with defaultProps. |
Alpha release - https://www.npmjs.com/package/recharts/v/2.13.0-alpha.0 Please use this alpha to see if defaultProps warnings are gone (and make sure things are still working as normal in R18 and below). For now, all the function components with issues have been wrapped with classes (while we work on 3.x) |
Works perfectly with R18, console errors disappear and no broken things found. Great job and thanks a lot. |
Nice! All credit to @eps1lon for the interim solution. Work still needed for things not to break in R19 so I'll wait for more feedback and see if we can get full support in before resolving this. Thanks everyone. |
https://www.npmjs.com/package/recharts/v/2.13.0-alpha.3 Please test this one as well on all React versions 16.8-19 to see if anyone runs into issues. Thanks! 🚀 |
Warning: XAxis: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead. |
Try installing the alpha version listed above |
@ckifer it worked! |
Hey y'all, I think installing
[UPDATE]: For React versions above R18, this works perfectly for me |
Console error is gone, thx a lot for the support! |
I'm going to close this since we have a path forwards to remove the errors Solution is Feel free to continue to report any issues found here (or R19 related here) Thanks all |
Using a library that include recharts v2.6.2 i get the following error in the console.
the charts are rendered normally thou.
The text was updated successfully, but these errors were encountered: