-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[bugfix] Update PropTypes import statements to use wildcard syntax #43701
[bugfix] Update PropTypes import statements to use wildcard syntax #43701
Conversation
Switched from default imports to wildcard imports for PropTypes across multiple files. This change ensures consistency in PropTypes usage and can help with tree-shaking during the build process. Bug Report: mui#43700
Trying the following in Node.js ( // test.mjs
import * as PropTypes from 'prop-types';
// import PropTypes from 'prop-types';
console.log(PropTypes.any); This prints 🤔 It's a bit strange, but these types don't look 100% correct to me. I'm seeing this change a long time ago. I'm wondering why they did that. I'm a bit worried making this change because I believe it could result in broken ESM once we move to #43264 |
@Janpot I cloned your forked repository https://github.com/Janpot/material-ui, checked out the Note: the current PR is functioning well when integrated into the main branch. |
We use But you can probably spare yourself the effort, try running the following script in Node.js: // ./test.mjs
import * as PropTypes1 from 'prop-types';
import PropTypes2 from 'prop-types';
import * as React1 from 'react';
import React2 from 'react';
console.log(!!PropTypes1.any, !!PropTypes2.any);
// false true
console.log(!!React1.useState, !!React2.useState);
// true true I believe |
@Janpot As a result, the build was successful. I must mention that I haven’t had much time to fully set up a Material UI application from the PR branch locally, including configuring all dependencies and executing the Nevertheless, I see no reason to reject this PR at this point now. Could you perhaps provide a guide on how to quickly install the I’ve merged your |
@Janpot Again my 2 cents, as Adopting Nevertheless, for supporting existing users who might rely on older configurations, consider employing versioning strategies. This way, newer versions can default to |
@Janpot While retesting locally with the TypeScript compiler and Webpack is a different scenario, yet even here approaches like Does this fit with our current solution? Just to note: as of now, Material UI v6.0.2 cannot be built with |
For #43264 the build command is
While working on this, the new mode is activated with a This is going to build a new file e.g. // test.mjs
import Button from '@mui/material/Button';
console.log(Button.propTypes); When you build from
When you build from When you run the commonjs variant, const Button = require('@mui/material/Button').default;
console.log(Button.propTypes); this will also just print the proptypes (because babel added an
This is the hard way of reproducing the problem. My little snippet from above essentially replicates what's happening inside of It'll be important to be able to load
I hope the long explanation makes it clear that the changes are not mergeable as for now. I understand this is frustrating. I believe the best next steps we could take is investigate why named exports in |
@morozow I think I figured out the problem with |
@Janpot You've highlighted some valuable ideas. I've tailored the solution to directly address the core issue with the We can either keep this current PR open for future reference or close it, depending on your preference. However, we should consider enhancing a codebase with a new PR by incorporating utilities to enable |
The problem has been fixed by updating the documentation: #43747 |
Switched from default imports to wildcard imports for PropTypes across multiple files. This change ensures consistency in PropTypes usage and can help with tree-shaking during the build process.
Replaced all occurrences of
import PropTypes from 'prop-types';
withimport * as PropTypes from 'prop-types';
in the entire Material UI codebase.Bug Report: [Error] Incorrect Import of PropTypes Causes Compilation Error