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

[codemod][base] Write a migration script for removal of component prop from components #36831

Merged
merged 14 commits into from
Apr 20, 2023

Conversation

hbjORbj
Copy link
Member

@hbjORbj hbjORbj commented Apr 10, 2023

Before

  • e.g.,
<InputUnstyled component='a' href='url'></InputUnstyled>;
  • e.g.,
<BadgeUnstyled
  component={CustomRoot}
  slots={{ badge: CustomBadge }}
/>;

After

  • e.g.,
<InputUnstyled<'a'> slots={{
  root: 'a'
}} href='url'></InputUnstyled>;
  • e.g.,
<BadgeUnstyled<typeof CustomRoot>
  slots={{
    root: CustomRoot,
    badge: CustomBadge
  }} />;

Breaking Changes

  • Base UI components no longer support component prop. The value passed to component must be transferred into slots.root.
  • Below is an example of how the migration should look like:
-<Input component={CustomRoot} />
+<Input slots={{ root: CustomRoot }} />

You can use this codemod to help with the migration.

@hbjORbj hbjORbj added package: codemod Specific to @mui/codemod package: base-ui Specific to @mui/base labels Apr 10, 2023
@hbjORbj hbjORbj marked this pull request as draft April 10, 2023 09:22
@mui-bot
Copy link

mui-bot commented Apr 10, 2023

Netlify deploy preview

https://deploy-preview-36831--material-ui.netlify.app/

Bundle size report

No bundle size changes

Generated by 🚫 dangerJS against 72dfac1

@hbjORbj hbjORbj self-assigned this Apr 13, 2023
@hbjORbj hbjORbj marked this pull request as ready for review April 13, 2023 10:52
const transformed = root.findJSXElements().forEach((elementPath) => {
// Process only unstyled components
if (
!elementPath.node.openingElement.name.name.endsWith('Unstyled') ||
Copy link
Member

Choose a reason for hiding this comment

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

This contradicts with the other codemod for removing this suffix, can be instead change the logic to look for imports from @mui/base?

Copy link
Member Author

@hbjORbj hbjORbj Apr 19, 2023

Choose a reason for hiding this comment

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

addressed: 3f88c6c

@@ -0,0 +1,25 @@
// @ts-nocheck
<Input component={CustomRoot} />;
Copy link
Member

Choose a reason for hiding this comment

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

We should not depend on the name of the component. It would be best to depend on the import.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can you elaborate? If you are talking about filtering base components, I changed the logic so we filter base components based on import statements.

@mnajdova
Copy link
Member

It's great that the changes are valid now as well, we don't have to sync the codemod with the changes we do per component.

@hbjORbj hbjORbj requested a review from mnajdova April 19, 2023 12:14
mnajdova and others added 2 commits April 19, 2023 17:34
Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

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

Looks good, let's merge!

@hbjORbj
Copy link
Member Author

hbjORbj commented Apr 20, 2023

Added the new codemod to README. Will merge once all CI tests pass.

@mnajdova
Copy link
Member

We can test in a separate PR to run the codemod in the docs (for e.g. to update all examples), as the result of the codemod is a valid API even now. Would you like to create a PR for it @hbjORbj?

@hbjORbj
Copy link
Member Author

hbjORbj commented Apr 20, 2023

Yes, sure :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: base-ui Specific to @mui/base package: codemod Specific to @mui/codemod
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants