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

[material-ui] Improve color map filter on styles #43579

Merged
merged 9 commits into from
Sep 10, 2024

Conversation

DiegoAndai
Copy link
Member

@DiegoAndai DiegoAndai commented Sep 2, 2024

Closes: #42698
Fixes: #41772

Improve the check of colors mapped for styles to avoid errors or invalid styles. Use a shared util for consistency.

Bug fix
Before: https://stackblitz.com/edit/stackblitz-starters-uk6qhx?file=src%2FApp.tsx
After: https://codesandbox.io/p/sandbox/epic-dijkstra-7frj4f?workspaceId=836800c1-9711-491c-a89b-3ac24cbd8cd8

@mui-bot
Copy link

mui-bot commented Sep 2, 2024

Netlify deploy preview

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

@material-ui/core: parsed: -0.07% 😍, gzip: 0.00% 😍

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against 7e95a90

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.

We should also update the following components:

  • Alert
  • ButtonGroup
  • Chip
  • Fab
  • FilledInput
  • FormLabel
  • IconButton
  • Input
  • LinearProgress
  • Link
  • OutlinedInput
  • PaginationItem
  • Switch
  • Typography

Was there a reason these were skipped? I just searched for "...Object.entries(theme.palette)" to find all occurences that needs to be updated.

@DiegoAndai
Copy link
Member Author

@mnajdova you're correct! Thanks for the review (I initially searched for filter([, palette] 😅). I added the missing components, as well as standardized the mappings of theme.palette in all components.

@DiegoAndai DiegoAndai added the cherry-pick to v5 The PR should be cherry-picked to the v5.x branch label Sep 3, 2024
@DiegoAndai
Copy link
Member Author

DiegoAndai commented Sep 6, 2024

@siriwatknp I'm debating whether to add a test for this and how to do it.

On the one hand, this is an edge case that we don't document and will stop working when we update the theme structure in v7. So, it feels too much of an edge case to add to describeConformance.

On the other hand, a regression was already reported about it, and if we wanted to add a test, it should run on all components, so in theory, it should exist in describeConformance.

I lean towards adding a test to describeConformance with a comment to remove when we update the theme structure, but I'm not sure. What do you think?

@siriwatknp
Copy link
Member

I lean towards adding a test to describeConformance with a comment to remove when we update the theme structure, but I'm not sure. What do you think?

yes, I agree.

@DiegoAndai
Copy link
Member Author

@siriwatknp we already have one 🎉 , so I only had to add the case from #41772: 982213f

Copy link
Member

@siriwatknp siriwatknp left a comment

Choose a reason for hiding this comment

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

Awesome!

@DiegoAndai DiegoAndai merged commit f91f4e5 into mui:master Sep 10, 2024
19 checks passed
@DiegoAndai DiegoAndai deleted the improve-color-map-filter branch September 10, 2024 17:25
Comment on lines 65 to 69
...Object.entries(theme.palette)
.filter(([, palette]) => palette && palette.main)
.filter(createSimplePaletteValueFilter())
.map(([color]) => ({
props: { color },
style: {
Copy link
Member

Choose a reason for hiding this comment

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

I guess we could replace all of these variant generations with CSS variables? https://caniuse.com/?search=css%20variables is compatible with https://mui.com/material-ui/getting-started/supported-platforms/#browser. I guess this could mean for CSS static extraction a smaller CSS output. For emotion, I'm not sure it would bring a lot of benefits.

Comment on lines -65 to +66
.filter(([, palette]) => palette && palette.main)
.filter(createSimplePaletteValueFilter())
Copy link
Member

@oliviertassinari oliviertassinari Sep 11, 2024

Choose a reason for hiding this comment

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

What's the impact on performance? I suspect this should be computed in the theme provider to process the theme and generate a list of compatible values only once, so it's cached.

Now, maybe with memoTheme it doesn't matter so much anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick to v5 The PR should be cherry-picked to the v5.x branch v6.x migration
Projects
Status: Done
5 participants