Skip to content

Remove or neutralize react 19 prop types#1

Merged
diedexx merged 2 commits intomainfrom
remove-or-neutralize-react-19-prop-types
May 12, 2025
Merged

Remove or neutralize react 19 prop types#1
diedexx merged 2 commits intomainfrom
remove-or-neutralize-react-19-prop-types

Conversation

@igorschoester
Copy link
Contributor

Context

In React 18.3, in preparation for React 19, the prop types are deprecated.
Specifically, propTypes and defaultProps will be removed for functions (though defaultProps will continue to be supported for class components)

https://react.dev/blog/2024/04/25/react-19-upgrade-guide#removed-deprecated-react-apis

We should adapt accordingly. I'm not entirely sure if that also mean the prop-types package will be unsupported.
Either way, we should:

  • remove our linting rule that requires propTypes (and defaultProps when not required).
  • refactor our defaultProps to be handled by defaults in the object instead. E.g. move to inline ES6.

We talked about it in the tech-council, see the meeting notes.

ESLint Rules

Fixes https://github.com/Yoast/reserved-tasks/issues/551

"react/no-unused-prop-types": "error",
"react/no-unused-state": "error",
"react/prefer-es6-class": "error",
"react/require-default-props": [ "error", { ignoreFunctionalComponents: true } ],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With ignoreFunctionalComponents being deprecated, lets use their replacement to enforce adopting the new way. Otherwise I fear we'll have a lot of default props to remove in one big sweep when it's time to switch to React 19.

// This will turn into an `error` in the future. It's a warning to give us time to adapt.
"react/require-default-props": [ "warn", { classes: "defaultProps", functions: "defaultArguments" } ],

We can set --max-warning thresholds and slowly work towards 0 warnings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with error. If consumers want to warn they can add an exemption for themselves?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed on Slack: we concluded that we slightly prefer warn over error: with error, all offending consumers would have to overwrite this rule, matching the arguments too. This means that we'll likely end up with 10 copies of the same rule. All copies will also need to be updated when it's time to more strictly enforce.
Having one central warn rule allows all consumers to just accept it and increase their max-warnings without copying and maintaining the rule definition.

@igorschoester igorschoester force-pushed the remove-or-neutralize-react-19-prop-types branch from d48ac28 to a327280 Compare May 12, 2025 12:16
`ignoreFunctionalComponents` is deprecated. Using `functions` instead.
This shifts the default prop checks for functions to the arguments instead.

Using warn to ease into the new arguments.
Due to it being in the recommended rules, just removing is not enough here.
@igorschoester igorschoester force-pushed the remove-or-neutralize-react-19-prop-types branch from a327280 to 87699db Compare May 12, 2025 12:46
@diedexx diedexx merged commit 26117c0 into main May 12, 2025
1 check passed
@igorschoester igorschoester deleted the remove-or-neutralize-react-19-prop-types branch May 12, 2025 13:10
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.

2 participants

Comments