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] Add sx prop for v6 migration #42153

Merged
merged 22 commits into from
May 27, 2024
Merged

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented May 7, 2024

Review suggestion

Please see the test cases (*.actual and *.expected). Feel free to suggest more test cases.

Implementation

Reuses some functions from styled and theme codemods. The logic is similar but require special treatment for some scenarios, e.g. there is no variants in sx prop.

@siriwatknp siriwatknp added the package: codemod Specific to @mui/codemod label May 7, 2024
@mui-bot
Copy link

mui-bot commented May 7, 2024

Netlify deploy preview

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

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against 7dc352f

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.

Some initial feedback and thoughts.


<Box
style={{
...props.style,
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this come last?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, the generated CSS vars should come last to ensure that it takes effect. It'd be 99.9999% that the CSS vars from props.style will get overridden.

Copy link
Member

Choose a reason for hiding this comment

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

I don't understand the argument honestly. Regardless of what the sx props generated, the users's style attribute should win, even if we almost never have cases where people need to do this.

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'm fine to change. As a note, it does not matter which way we choose to override (before or after) because if the generated variable is the same as their existing style.*, the result styles will not be the same but as I said, that's 99.9999%.

For example,
Before:

<Box
  style={{
    '--items-imageLight': '10px', // existing user's defined variable 
  }}
  sx={{
    fontSize: 'var(--items-imageLight)',
    backgroundImage: (theme) =>
      theme.palette.mode === 'light'
        ? items[selectedItemIndex].imageLight
        : items[selectedItemIndex].imageDark,
  }}
/>;

After:

<Box
  style={{
    "--items-imageLight": items[selectedItemIndex].imageLight,
    "--items-imageDark": items[selectedItemIndex].imageDark,
    '--items-imageLight': '10px', // existing user's defined variable
  }}
  sx={theme => ({
    fontSize: 'var(--items-imageLight)',
    backgroundImage: "var(--items-imageDark)",
    ...theme.applyStyles("light", {
      backgroundImage: "var(--items-imageLight)", // ❌
    })
  })}
/>;

@siriwatknp siriwatknp marked this pull request as ready for review May 8, 2024 09:51
Copy link
Member

@DiegoAndai DiegoAndai left a comment

Choose a reason for hiding this comment

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

Sorry for the delay on the review @siriwatknp

Comment on lines 6 to 7
'& .MuiAccordion-region': {},
'& .MuiAccordionDetails-root': {},
Copy link
Member

Choose a reason for hiding this comment

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

Are these empty object required?

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me improve on this.

Copy link
Member Author

Choose a reason for hiding this comment

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

@siriwatknp
Copy link
Member Author

@mnajdova @DiegoAndai Could you do another review?

Copy link
Member

@DiegoAndai DiegoAndai 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! Only one small nit pick


describe('@mui/codemod', () => {
describe('v6.0.0', () => {
describe('basic sx-v6', () => {
Copy link
Member

Choose a reason for hiding this comment

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

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 did not know it existed. To be honest, I prefer writing test separately instead of using .forEach. The reason is debugging.

With multiple it(), you can use .skip or .only to debug a test (I frequently do this all the time), but it's not possible with .forEach. If you have a way to debug each test but still using .forEach, I'm all ears.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label May 27, 2024
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label May 27, 2024
@siriwatknp siriwatknp merged commit 20d6b5e into mui:next May 27, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: codemod Specific to @mui/codemod
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants