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

Remove defaultProps which are deprecated in React #128

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

vieira
Copy link

@vieira vieira commented Aug 30, 2024

Drop defaultProps from the generated component as they are now deprecated and will be removed in React 19.

They were added in #8 due to concerns about the overhead of _extends although no benchmarks were provided and it is likely that difference would be marginal where it matters.

Fixes: #126

Drop defaultProps from the generated component as they are now
deprecated and will be removed in React 19.

They were added in airbnb#8 due to concerns about the overhead of `_extends`
although no benchmarks were provided and it is likely that difference
would be marginal where it matters.

Fixes: airbnb#126
@vieira vieira force-pushed the 126-remove-deprecated-default-props branch from fcc0d0d to 0038070 Compare August 30, 2024 15:09
@ljharb
Copy link
Collaborator

ljharb commented Aug 30, 2024

This seems like it'd be a breaking change, and React 19 isn't out yet (prereleases don't count).

Instead of dropping them, there should be an option that skips them.

@vieira
Copy link
Author

vieira commented Aug 30, 2024

Can you provide an example where this would be a breaking change?

I don’t think there is much point of making it an option given that React has already deprecated them in the current release. This change, afaik, won’t break old React versions, will stop the warnings in the current release, and will keep working in the next release (19.x).

@ljharb
Copy link
Collaborator

ljharb commented Aug 30, 2024

"deprecated" is irrelevant, that's just a warning. They still work in React 18.

The breaking change is one of the reasons it's a terrible idea to get rid of defaultProps from react - you can reflect on defaultProps from the outside, you can't read default arguments.

@vieira
Copy link
Author

vieira commented Aug 30, 2024

They “work” but not without filling the console with warnings. This is not a question of agreeing or disagreeing with react team on the removal of defaultProps as that decision was already made by them.

If you can provide any concrete examples of how this is a breaking change maybe I can try to address them. Existing tests are passing.

@ljharb
Copy link
Collaborator

ljharb commented Aug 30, 2024

Basically, .defaultProps on the component needs to have the same values in it, or else it's a breaking change - but that's what causes React to emit warnings.

I think the only reasonable approach here is to add an option so you can opt in to "no defaultProps".

@vieira
Copy link
Author

vieira commented Aug 30, 2024

I don’t think the public/documented API of this plugin is in any way affected by the removal of defaultProps, but I have no problem in delaying this until the next major.

For me it does not make much sense to add a new option that we already know will not work in the next React version.

@ljharb
Copy link
Collaborator

ljharb commented Aug 30, 2024

The new option would be "no defaultProps" - ie, it'd be required in the next React version.

@BenColwell131
Copy link

Is there a way to stop the flood of console warnings on this in the meantime?

@ljharb
Copy link
Collaborator

ljharb commented Sep 6, 2024

I'm fine with updating this PR to have an option that skips the defaultProps - that would allow you to avoid the warnings.

@BenColwell131
Copy link

That would be ideal. Makes it quite painful to debug other issues amongst this.

@ljharb ljharb marked this pull request as draft September 9, 2024 14:59
@GoudekettingRM

This comment was marked as spam.

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.

defaultProps is deprecated for fn components
4 participants