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

[theme] Remove createV4Spacing from adaptV4Theme #27072

Merged
merged 2 commits into from Jul 9, 2021

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented Jul 2, 2021

createSpacingV4 conflicts with theme-spacing codemod

  • theme-spacing codemod will remove px from theme.spacing(...) which is correct for v5
  • there is a function createSpacingV4 in adaptV4Theme that force theme.spacing(...) to not return px

As a result, you currently cannot use codemod together with adaptV4Theme.

@siriwatknp siriwatknp added the package: material-ui Specific to @mui/material label Jul 2, 2021
@mui-pr-bot
Copy link

mui-pr-bot commented Jul 2, 2021

Details of bundle changes (experimental)

Generated by 🚫 dangerJS against e51551c

@@ -207,11 +207,11 @@ describe('adaptV4Theme', () => {
}).toWarnDev(['adaptV4Theme() is deprecated']);

expect(transformedTheme.mixins.gutters()).to.deep.equal({
paddingLeft: defaultSpacing * 2,
paddingRight: defaultSpacing * 2,
paddingLeft: `${defaultSpacing * 2}px`,
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this a breaking change?

Copy link
Member Author

Choose a reason for hiding this comment

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

I would say yes, for people who are using adaptV4Theme. This PR should be released together with the updated codemod, I think.

Copy link
Member Author

Choose a reason for hiding this comment

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

Once they run the codemod again, it should be fine.

Copy link
Member

Choose a reason for hiding this comment

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

So adaptV4Theme requires running the codemod now?

Copy link
Member Author

Choose a reason for hiding this comment

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

If this change has merged, yes. Codemod is required to run (or manually remove "px" from {theme.spacing(2)}px).

Copy link
Member

Choose a reason for hiding this comment

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

But then why would I use the helper? This seems a bit odd that adaptV4Theme requires the codemod and is otherwise broken. Either we make it so that I can apply runtime helper and codemod separately or we remove either one. But this two-step process is prone to user-error i.e. our fault.

Or we tell people nothing about adaptV4Theme and let the codemod apply it. Or rather tell people to not use adaptV4Theme manually.

Copy link
Member Author

@siriwatknp siriwatknp Jul 6, 2021

Choose a reason for hiding this comment

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

Or we tell people nothing about adaptV4Theme and let the codemod apply it. Or rather tell people to not use adaptV4Theme manually.

If I get it right, you are correct. This codemod version #27032 will automatically add adaptV4Theme to the codebase and also remove px from ${theme.spacing(...)}px (with one command). But there is problem because the adaptV4Theme replace .spacing() with v4 behaviour, then the css will be like padding: 10.

This PR will remove the v4 behaviour so projects that haven't migrated can run codemod once and it works.

The only breaking will be the people who already migrate to v5 AND is using adaptV4Theme (which I believe that it is a few). For this group, we can add info to next release note that they should run codemod once more.

Is this clear to you?

Copy link
Member Author

Choose a reason for hiding this comment

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

There is another option, which does not need this PR.

The codemod does not fix the theme.spacing and let adaptV4Theme do it. However, once they complete migration and they want to remove adaptV4Theme, they will need to remove px from theme.spacing manually or run a separate codemod.


In my opinion, I favor the one-time codemod.

Copy link
Member Author

Choose a reason for hiding this comment

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

@eps1lon is this sounds good to you?

@oliviertassinari oliviertassinari changed the title [Theme] remove createV4Spacing from adaptV4Theme [theme] Remove createV4Spacing from adaptV4Theme Jul 5, 2021
Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

After these changes, adaptV4Theme "bridges" fewer cases, but it makes using the codemod simpler.

IMHO, being able to use adaptV4Theme + the codemod without any second thoughts is, overall, a net improvement (but no strong point of view).

@siriwatknp siriwatknp requested a review from eps1lon July 8, 2021 07:17
@siriwatknp siriwatknp merged commit a57332a into mui:next Jul 9, 2021
@siriwatknp siriwatknp deleted the remove-spacing-adaptv4 branch July 9, 2021 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants