[react 19] checkPropTypes, ensure runtime warning continuity
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 99.1k
- Forks
- 32.5k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 106
Description
Steps to reproduce
Link to live example: https://codesandbox.io/s/frosty-snowflake-zjl49r?file=/src/Demo.js
Steps:
- Take the example in https://github.com/mui/material-ui/pull/43022#discussion_r1687208774 with React 19
<Slide direction="up" in={checked} mountOnEnter unmountOnExit>
<p>sample</p>
<p>sample</p>
</Slide>
-
Toggle the switch
-
Check the errors
but nothing tells you how to fix it.
Current behavior
No information on what is wrong.
You could argue that TypeScript will let you know ahead of time, but what if you get the type wrong? At least, from this issue, we can collect upvotes from developers who faced the same challenge.
Expected behavior
A clear error message.
Context
- On the removal of the propTypes check in React 19: https://github.com/facebook/react/issues/28992.
- Cases of doing error messages not the right way: https://github.com/mui/mui-x/pull/13911, https://github.com/mui/mui-x/pull/12992. It's not a so simple problem to solve.
- The future of prop-types: https://www.notion.so/mui-org/RFC-Discontinue-use-of-prop-types-ea106ba181704688ad70b155919ce4e1
- Possible simple solution with a new helper:
diff --git a/packages/mui-material/src/Slide/Slide.js b/packages/mui-material/src/Slide/Slide.js
index d669e811d6..f316556579 100644
--- a/packages/mui-material/src/Slide/Slide.js
+++ b/packages/mui-material/src/Slide/Slide.js
@@ -1,6 +1,8 @@
'use client';
import * as React from 'react';
import PropTypes from 'prop-types';
+import getDisplayName from '@mui/utils/getDisplayName';
+import checkPropTypes from 'prop-types/checkPropTypes';
import { Transition } from 'react-transition-group';
import chainPropTypes from '@mui/utils/chainPropTypes';
import HTMLElementType from '@mui/utils/HTMLElementType';
@@ -82,11 +84,20 @@ export function setTranslateValue(direction, node, containerProp) {
}
}
+function muiCheckPropTypes(Component, props) {
+ if (process.env.NODE_ENV === 'production') {
+ return;
+ }
+ if (React.version >= '19') {
+ return checkPropTypes(Component.propTypes, props, 'prop', getDisplayName(Component));
+ }
+}
+
/**
* The Slide transition is used by the [Drawer](/material-ui/react-drawer/) component.
* It uses [react-transition-group](https://github.com/reactjs/react-transition-group) internally.
*/
-const Slide = React.forwardRef(function Slide(props, ref) {
+const Slide = React.forwardRef(function SlideIn(props, ref) {
+ if (process.env.NODE_ENV !== 'production') {
+ muiCheckPropTypes(Slide, props);
+ }
+
Your environment
"@emotion/react": "11.13.0",
"@emotion/styled": "11.13.0",
"@mui/material": "5.16.6",
"react": "19.0.0-rc.0",
"react-dom": "19.0.0-rc.0"
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with packages/mui-material/src/Slide/Slide.js and the React 19 propTypes-removal context linked in the issue. Reproduce the warning with the linked CodeSandbox and inspect the suggested checkPropTypes approach. Done means the React 19 example reports a clear, actionable runtime error rather than only a generic warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100