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

[RFC] Material-UI v5 🚀 #20012

Closed
oliviertassinari opened this issue Mar 6, 2020 · 92 comments
Closed

[RFC] Material-UI v5 🚀 #20012

oliviertassinari opened this issue Mar 6, 2020 · 92 comments
Labels
umbrella For grouping multiple issues to provide a holistic view
Milestone

Comments

@oliviertassinari
Copy link
Member

oliviertassinari commented Mar 6, 2020

Introduction

Material-UI v4 was released 10 months ago, per our release schedule. It's time to plan for v5.
Our GitHub milestone has a due date for October 1st 2020, and while I doubt we will release in time, planning 6 months ahead seems relevant.

Developers made it clear in the past that they don't enjoy breaking changes. This is feedback we took into consideration when designing our versioning strategy, and for each minor/patch releases. The result was to commit to a minimum of 1 year between each major release.

At the same time, the v0 to v1 upgrade was a major breaking change (a rewrite with a brand new API) and yet it was successful. I think that we should be willing (taking the risk) to make bold changes, as long as they fit in the direction we see the community going in the long term (with Material-UI empowering it).

Structural changes

1. Unstyled components

Similar to Angular Material CDK components (Component Development Kit) #6218.

In practice, it could be a new hook version of all the components, something we have started to experiment with the useAutocomplete and usePagination in the lab.

The problem:

  • The React OSS component community is fragmented. You will find both standalone components for a specific problem, as well as and a growing number of component libraries, with a wide range of API consistency, a11y, bug density, performance, bundle size, quality, and support.
  • Styling solution usage is fragmented. We can get a glimpse of this by looking at the CodeSandbox usage stats for the style interoperability page:
    • plain css: 34%
    • styled components: 30%
    • global css: 18%
    • css modules: 12%
    • emotion: 5%
  • Developers and designers use different design systems. Material Design doesn't have a monopoly.
  • How can we help with the unstyled story of notistack, raised by @iamhosseindhv?

Why this solution?:

  • This will enable Material-UI to stay relevant in the long term. This is a cornerstone of our strapline. It will shift the developer's perception, that Material-UI is, at its core, about providing material to build UIs.

React components for faster and easier web development. Build your own design system, or start with Material Design.

  • Talking with backend and fullstack users, we know that they are craving for a single component store rather than having to deal with a wide range of dependencies. We could expect the same from front-end developers.
  • This new "offering" should better resonate with front-end developers. We could expect to gain more and higher quality contributions from the front-end community thanks to this shift.
  • Based of our current trust, usage, and exposure in the React community, we are well-positioned to gain usage with this new "offering".
  • Maintaining standalone components is rarely sustainable. I have seen too many projects left abandoned. But by aggregating them in Material-UI, it helps our flywheel. It can incentivize new maintainers to work on the OSS. It can also strengthen our current monetization channels and invest resources back into the OSS components.
  • It's important to support different style engines and design systems.

2. Full strict mode support

#18018, #13394

The problem:

  • While developers can set up strict mode in their app to identify incorrect patterns, Material-UI prevents them from keeping this mode enable on a daily basis, as there would be too much noise in the console. We have, for example, disabled it for the Material-UI documentation.

Why this solution?

  • It's the future.
  • It helps with the unstyled story.

3. Migrate to styled-components

#6115, #16947

The problem:

  • We have left important issues related to our styling solution unhandled over the last few months: streaming, strict mode, performance, CSS template support, style functions, class name mismatch, etc.
  • We need to support dynamic props, this is important for the features we want to implement on the components.
  • JSS popularity didn't stick with the front-end community.

Why this solution?

  • A migration to styled-components is our most requested (upvoted) issue to date.
  • We want to remove the need for the majority of developers to bundle two CSS-in-JS runtimes.

It could be interesting to provide a choice between different style engines. v5's users would be able to replace @material-ui/styles with react-jss.

4. Enable the use of @material-ui/system's props in the core components

#15561

The problem

  • Naming things is hard.
  • Indirections can be inefficient.

Why this solution?

This is mainly driven by the positive feedback Tailwind and styled-system have had recently in the community. I enjoy the pattern a lot for one-off layout problems. It's frustrating that only the Box component supports it. I think that it should also cover #6140.

<Typography textAlign={{ xs: 'left', md: 'center' }} />
<Button mt={3}>

Regarding the implementation and final API, we could still reconsider the tradeoff (relying on global class names rather than style functions).

5. Allow the use of dynamic theme variants and colors

#15573 & #13875. Allow breakpoints customization #11649.


I was wondering about revamping the theme structure to match System-UI Theme Specification
but we don't see a clear win so far.

Material-UI's theme structure, on its own, is a specification, the structure is set.
Assuming that Material-UI aims to support a wide range of components (unstyled or not), matching this spec, not just Material Design,
I fail to see a strong advantage a different constraint could yield.

On the cost side, using theme-specification would require to drop some of the features of our theme and require breaking changes.
The benefit isn't obvious, but it's something to consider.

Regarding styled-system. I think that we should re-evaluate if we still need @material-ui/system.

Material Design

✅ Checklist

Lab to core components

I think that we can aim to move the following components from the lab to the core:

✅ Components

The only component I have would propose to handle later on is the TreeView.
We still have a couple of important features to implement, and might need to change the API to ship these features. Once we do, we'll start to get more adoption, so the more likely it is that developers will uncover root issues.

Supported browsers

While we plan to keep IE 11 support until v6,
We will look into proposing different proposing entry points #18447.
and if we can drop older browsers' versions #15496.

Deprecations

✅ List of breaking changes we can introduce with a deprecation during v4.

For a list of committed breaking changes and associated deprecations, see: #22074

Breaking changes

Unlike the previous section, these are breaking changes we can't gracefully warn against.


Timing

I think that we can try the following:

  1. Deprecation preparation. (starts now)
  2. Create the next branch, publish the next versions under https://next.material-ui.com/ and the next npm tag. (April?). Stop all efforts on the v4.x version. Put the master branch (v4.x) in a low maintenance mode, only handle security fixes.
  3. Work on the above items, in whatever order is simpler, keep the same release schedule, once a week, with alpha first.
  4. Once we have handled all the breaking changes and confidence with the architectural choices move to a beta stage. Once we are confident with the implemented features, start release candidates.
Current progress 109/109
Array.from(document.querySelectorAll('.contains-task-list')[2].children)
.concat(Array.from(document.querySelectorAll('.contains-task-list')[3].children))
.concat(Array.from(document.querySelectorAll('.contains-task-list')[1].children))
.concat(Array.from(document.querySelectorAll('.contains-task-list')[0].children))
.reduce((acc, item) => {
  if (item.querySelector('input[type="checkbox"]:checked')) {
    acc.done += 1;
  }
  acc.total += 1;
  return acc;
}, { total: 0, done: 0 });
@oliviertassinari oliviertassinari pinned this issue Mar 6, 2020
@oliviertassinari oliviertassinari added the umbrella For grouping multiple issues to provide a holistic view label Mar 6, 2020
@oliviertassinari oliviertassinari added this to the v5 milestone Mar 6, 2020
@ValentinH
Copy link
Contributor

Really detailed plan and it looks good to me.

The only thing that scares me about is the styled component part.

v5's users would be able to replace @material-ui/styles with react-jss.

Does react-jss includes all the features of @material-ui/styles? Specifically the awesome TS support for the return type of useStyles()?

@dmtrKovalenko
Copy link
Member

dmtrKovalenko commented Mar 7, 2020

Unstyled components

I think that providing hooks is not a really best solution for making custom design systems. I know that some companies using material-ui like

// packages/design-system
export * from '@material-ui/core'

export const ThemeProvider = ({ ...props }) => 
  <ThemeProvider theme={ourCustomStyledMuiTheme()} /> 

// then in app code
import { Button } from '@my-project/design-system' 

And this is a really powerful way to build custom design, based on best practices and documentation of material-ui. The main problem here is only bundlesize bloating. You have no way to remove from the bundle overridden css. Unstyled components can solve this problem just fine.

But the proposed solution with hooks will may them to write custom components, custom dom structure – that’s why I don't think it will not become really popular.

Should it work something like this? This will make building design system overcomplicated and require everybody to rebuild html structure, which in its turn can break accessibility 😢

import { useButton } from '@material-ui/core'

const buttonProps = useButton()
export const Button = () => <button {...buttonProps} /> 

Proposal

I propose to provide an additional exported components but without any css. So they will be just empty html components with the logic. Thus any company will be able to handcraft custom design for provided components and use all the power of material-ui accessibility, types, documentation and so on.

export * from '@material-ui/core/unstyled'

How? For example, we can make a custom babel plugin that will, for example, remove all the css code from components and will leave only class names.

@yordis
Copy link
Contributor

yordis commented Mar 8, 2020

Personally, before tackling the unstyled components, I would make sure to divide it into two categories: Behavioral and UI. Or at least have clear boundaries about this in the source code, now with hooks, probably most things would become as part of a hook rather than as part of the component body.

Behavioral components expose functionality either by hooks or by elements that don't affect the UIs as much, for example, Slider, Click Away Listener, Popovers, Portals.

While UI is purely how things look.

@oliviertassinari
Copy link
Member Author

Does react-jss includes all the features of @material-ui/styles? Specifically the awesome TS support for the return type of useStyles()?

@ValentinH I don't have the details on this question. If it doesn't, it will be a great opportunity to port these advantages back to react-jss.

I think that providing hooks is not a really best solution for making custom design systems.

@dmtrKovalenko I like the proposal. I have been wondering about going into this direction. I think that solving this problem will be very interesting, it's a complex problem with many use cases to consider and strong tradeoffs to take. In any case, I doubt that hooks can be 100% of the answer.

@saulshanabrook
Copy link

saulshanabrook commented Mar 27, 2020

We are considering using Material UI in JuyterLab (jupyterlab/jupyterlab#7574) and was wondering about this point:

It could be interesting to provide a choice between different style engines. v5's users would be able to replace @material-ui/styles with react-jss.

This sounds like an interesting and useful idea and I am curious if other libraries provide compatibility with different style engines. Ideally, it would be nice to be able to switch dynamically between these frameworks and just generating plain CSS, by just changing some config or build value and not having to rewrite all our components. 🤷‍♂

However, I haven't though very deeply about the topic. Please let me know if this has already been discussed somewhere. Also curious if other libraries have experimented with this technique.

@oliviertassinari
Copy link
Member Author

Also curious if other libraries have experimented with this technique.

@saulshanabrook I'm not aware of any deployed prior work on this matter.

We are considering using Material UI in JuyterLab (jupyterlab/jupyterlab#7574) and was wondering about this point:

This is awesome, I'm going to following this thread to see if I can bring in any facts.

@balazsorban44
Copy link
Contributor

Really well-written!

I have a proposal(?) for:

[theme] Rename theme type -> mode. While the spec use "schema", saying "dark mode" seems to be more common, e.g https://css-tricks.com/dark-modes-with-css/.

I recently started implementing dark mode for our project at our company, and more than once (actually pretty much all the time) I do either of these:

  1. When accessing theme.palette.type is to check for theme.palette.type === "dark", and write it to a isDark (doing this inside makeStyles(), when I create classes for components),
  2. I use a custom hook useTheForce().isDark (🤓) (which is just useTheme().palette.type === "dark")

Would it be easier to just expose theme.palette.isDark (name can be anything) as a boolean, either next to the proposed theme.palette.mode or dropping mode entirely. Is it possible to implement more than light and dark at all? If yes, I can understand the reason behind using a string, otherwise one have to write some boilerplate to access this simple true or false value.

Do tell if there is a reasoning behind it, or I could do better than the above-mentioned options.

Looking forward to Material UI v5! 🎉

@oliviertassinari
Copy link
Member Author

@balazsorban44 Interesting, we could extend the discussion to theme.direction === "rtl" vs theme.isRtl.

@balazsorban44
Copy link
Contributor

balazsorban44 commented Apr 5, 2020

I don't have a case for that (yet?), but that looks to be the same situation, yes.

Except maybe that there are only right-to-left and left-to-right. I guess theoretically it is allowed to add more than "light" and "dark" options to mode though, or is there any underlying restriction (Can MUI handle more than two modes?) Still, I would argue that accessing dark mode is so common that it should be exposed as a boolean.

Are there any reasons not to include both (the proposed mode as a string and an isDarkMode boolean) variants?

Also, is it possible to expose an accompanying function (eg.: changeMode) to be able to quickly change between modes (and RTL)? Right now, one has to use createMuiTheme in some kind of a provider above ThemeProvider that has a simple mode state (which is used to toggle the passed theme to ThemeProvider) and a setMode setter, that can be used to switch between modes from anywhere in the app). If a setter would be exposed on useTheme(), an extra context could be spared here, as this only "syncs" the mode's state in ThemeProvider.

@oliviertassinari
Copy link
Member Author

@balazsorban44 thank you for bringing your perspective on the matter. It's also interesting to look at the strategy we had in v0: https://v0.material-ui.com/#/customization/themes. Considering the idea that we want to provide multiple themes (Material Design, Gmail, Firebase, Material Studies, Fluent, Ant Design, Chakra, Bootstrap, High contrast, etc), we could consider handle the dark mode as a standalone theme 🤔.

is it possible to expose an accompanying function (eg.: changeMode) to be able to quickly change between modes (and RTL)?

See the discussion in #20495.

@popuguytheparrot
Copy link

I'm Concerned for DX in Developer Tools.
I would like to avoid such nesting without to the use of filters.
For example, if this possible to change hoc withStyles to hook, and forward ref to hook.
Fix Anonymous names.

image

@eps1lon

This comment has been minimized.

@popuguytheparrot
Copy link

I wrote about it. The solution through the filter does not solve the problem. it is important to refuse in favor of hooks

@mwhitney-butter
Copy link

i've searched far and wide for any issues or tasks regarding migrating the DataGrid component to v5 but havent found any yet. I've started a brand new project currently using the beta version of @material-ui/core@next and everything was fine until i tried to use the DataGrid. i get an error if i don't have the old material styles package installed specifically for the DataGrid. what's the plan for DataGrid?

@nguyenvanthanh97

This comment has been minimized.

@oliviertassinari
Copy link
Member Author

oliviertassinari commented Jul 11, 2021

i've searched far and wide for any issues or tasks regarding migrating the DataGrid component to v5 but havent found any yet.

@mwhitney-butter The data grid component is compatible with v5, as you can see in this demo https://codesandbox.io/s/material-demo-forked-tiwo9. However, it still relies on JSS, we haven't migrated to emotion yet. We have this milestone to make progress with a perfect integration with v5: https://github.com/mui-org/material-ui-x/milestone/10.

This issue mui/mui-x#1902 might be the one you are the most interested in. The current target is to drop v4 support in the data grid once v5 is stable.

@jedwards1211
Copy link
Contributor

jedwards1211 commented Jul 11, 2021

I don't think I'll ever have time to migrate my entire app to Emotion. It looks like I can keep using the JSS stuff via @material-ui/styles if I upgrade to v5, but that would mean both Emotion and JSS wind up in my app bundle, right? That would be too much, I'll have to stick with v4 if that's the case. If I run into issues with v4, will I be out of luck for any fixes though?
(Or will there be continued v4 support via a Tidelift subscription?)

@oliviertassinari
Copy link
Member Author

oliviertassinari commented Jul 12, 2021

@jedwards1211 We only fix major issues on the core components of v4 (we haven't fixed a lot in 12 months, to be honest). This is done to avoid version fragmentation in the community.

@eric-burel
Copy link
Contributor

I am investigating v5 styled API. I've been using Styled Components for a while (~2017), so I am progressively trying to adapt to new patterns.

At this point I think there is a (perfectly normal) lack of guidelines about styling our own components.

  • Will makeStyles be progressively deprecated? It has an important place in the v5 docs at the moment https://next.material-ui.com/styles/basics/
  • On the contrary, styled tag as a small place while many people are currently using either Styled Components or Emotion styled tag. https://next.material-ui.com/system/styled/
  • No doc about the string template syntax (while from my experiment it seems to work). It would be nice to keep the same behaviour as Styled Components and even maybe keep using the same syntax highlighting plugins. I don't know what Emotion proposes but I guess it's similar.
  • Best practices might need to be translated. For instance, I've just found out this gold article from Josh Comeau (https://www.joshwcomeau.com/css/styled-components/), but I am not sure how to translate into Material UI styled. Using the string template approach would probably help as many learning resources coming from Styled Components are using this syntax (another one I loved: https://frontendmasters.com/courses/design-systems/)

@EddyVinck

This comment has been minimized.

@oliviertassinari

This comment has been minimized.

@CloutProject
Copy link

I merged my entire codebase to Material-UI v5 and everything went well. However, there is one thing that annoyed me: the styled api doesn't seem to support styled-components syntax for regular html tags (where you use a dot instead of parentheses). For instance: one would expect to be able to do the following:

const MyStyledComponent = styled.div`
  padding: 16px 24px;
`;

I know I can achieve the same behavior with the parentheses syntax, but is there any particular reason why we cannot use the dotted one?

@oliviertassinari
Copy link
Member Author

@CloutProject Note that not all the styled implementation supports this shortcut, e.g. https://github.com/cristianbote/goober#comparison-and-tradeoffs. Goober doesn't support it in the base package to minimize bundle size.
It also leads to two way to do the same things, developers are left wondering if they should either use styled('div') or styled.div. 👍 for not supporting this API.

An issue slightly related: #23220.

@mnajdova
Copy link
Member

Looks like all planned work has finished, so we believe we can close this one.

@dimitropoulos
Copy link
Member

@oliviertassinari (cc: @CloutProject) I think the point you make is very valid, however the problem is that the styled.div syntax is far far far more common. The styled-components docs pretty much exclusively uses this syntax. I also hit this when I upgraded to v5 (and, frankly, just in daily usage) because I'm so used to the standard styled-components API.

I agree with the decision to just have one consistent way to do things (e.g. styled('div')) but it might be worth a bit more consideration (maybe, I'm thinkin' some more calling-out in the docs?) for how deeply ingrained the styled.div-style API is for many people.

Is there some way that we can add the type for things like styled.div that's never (so that no one can accidentally use it) and deprecated, but points people in the right direction that might not be able to immediately figure it out?

Screenshot_20210816_105612

@eric-burel
Copy link
Contributor

eric-burel commented Aug 16, 2021

@dimitropoulos related to my previous comment, I think the question that should be answered first is whether most people should actually use Material UI's styled, since Material UI is a library of component and a design system, but not a technical solution for CSS-in-JS.
It's great that MUI happen to expose their abstracted API. It could be a nice fit if you develop your own library of components for instance, as you would enjoy the same benefits (replace-ability of the underlying styling engine is really something great).

But this abstracted API has been built to develop this library of components, not as a go-to solution for styling anything. Limitation is that it might be simplified compared to a full-fledged engine, and less "safe" as it is not necessarily meant to be used by zillions of developers on a daily basis.

So maybe the right solution, when developing an application that uses Material UI, is to directly use your preferred engine styled function directly, not Material UI abstracted version.

(that's my personal interpretation though, I don't know the Material UI developers intents)

@mnajdova
Copy link
Member

@eric-burel does this page on the docs explain a bit more when you may need to use the styled() we expose?

@eric-burel
Copy link
Contributor

eric-burel commented Aug 16, 2021

Partly yes, this is my understanding currently of the section "What problems does it solve?":

  1. It uses Material-UI's default theme if no theme is available in React context.

I think that it could be done by reexporting Emotion/SC styled function but with the right typings/default values. Haven't tried yet.

  1. It supports the theme's styleOverrides and variants to be applied, based on the name applied in the options (can be skipped).

Didn't fully grasped the consequences of this. Doesn't it apply only when trying to restyle Material UI components?

  1. It adds support for the the sx prop (can be skipped).

Ok, this one is interesting, because it allows to have a unified syntax between Material UI components, and user-defined components with this sx prop.

  1. It adds by default shouldForwardProp option that is taking into account all props used internally in the Material-UI components (can be overridden).

Same as 2., I am not 100% sure what it means but it sounds like it's mostly useful when restyling Material UI components, or user-defined components that use Material UI?

I clearly see the improvements from Material UI v4 and this is very exciting!

But now that you use Emotion/Styled Components under the hood, I'd be tempted to look for an alternative approach where you maintain those 4 key points, but using Emotion/Styled Components styled function instead.

I'd be more convinced if you proved that it's not technically possible to enjoy those 4 features by extending Emotion/SC styled somehow, and that using Material UI styled is really the only right way to do this.

@oliviertassinari
Copy link
Member Author

Could we follow up on this discussion in a new GitHub issue? One that focuses on #20012 (comment). It would allow us to keep the scope small, so others can find it and contribute.

@ghost
Copy link

ghost commented Sep 11, 2021

Can someone tell me what happened in v5? The old look of the site was amazing but https://next.material-ui.com/ looks terrible to me in terms of "Material" (mostly the component styles but colors do matter too). This is just my opinion and I don't want anyone to be affected by it. Is it simply using a custom theme or have all the styles been changed?

@oliviertassinari
Copy link
Member Author

oliviertassinari commented Sep 11, 2021

@sharedrory We are getting rid of this homepage for a new one with the v5 stable release. Please ignore it.
Regarding what happened in v5, we are covering a high-level overview in #27912.

@dkadrios
Copy link

I actually like the new doc pages 😀

My only (long standing) complaints revolve around the search feature. If you start typing a component name, then the top result is the API page which is usually what I'm after, but if you finish typing an exact match it goes away. e.g. type "gri" and the Grid API page is top, but type "grid" and poof.

I also wish hitting ENTER would open the top result. I can down-arrow to select and then press enter to open it, but I'm super lazy 🙃

@siriwatknp
Copy link
Member

My only (long standing) complaints revolve around the search feature

Thanks for the feedback, I am looking into it. #16502

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
umbrella For grouping multiple issues to provide a holistic view
Projects
None yet
Development

No branches or pull requests