Skip to content

[RFC] Material-UI v5 πŸš€Β #20012

Closed
Closed

Description

@oliviertassinari

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 });

Activity

  1. added
    umbrellaFor grouping multiple issues to provide a holistic view
    on Mar 6, 2020
  2. added this to the v5 milestone on Mar 6, 2020
  3. ValentinH commented on Mar 7, 2020

    @ValentinH
    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()?

  4. dmtrKovalenko commented on Mar 7, 2020

    @dmtrKovalenko
    Collaborator

    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.

  5. yordis commented on Mar 8, 2020

    @yordis
    Contributor

    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.

  6. oliviertassinari commented on Mar 23, 2020

    @oliviertassinari
    MemberAuthor

    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.

  7. saulshanabrook commented on Mar 27, 2020

    @saulshanabrook

    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.

  8. oliviertassinari commented on Mar 27, 2020

    @oliviertassinari
    MemberAuthor

    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.

  9. balazsorban44 commented on Apr 5, 2020

    @balazsorban44
    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! πŸŽ‰

  10. oliviertassinari commented on Apr 5, 2020

    @oliviertassinari
    MemberAuthor

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

  11. balazsorban44 commented on Apr 5, 2020

    @balazsorban44
    Contributor

    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.

  12. oliviertassinari commented on Apr 12, 2020

    @oliviertassinari
    MemberAuthor

    @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.

  13. popuguytheparrot commented on Apr 13, 2020

    @popuguytheparrot

    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

  14. eps1lon commented on Apr 13, 2020

    @eps1lon
  15. 72 remaining items

  16. oliviertassinari commented on Jul 21, 2021

    @oliviertassinari
    Author
  17. CloutProject commented on Aug 15, 2021

    @CloutProject

    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?

  18. oliviertassinari commented on Aug 15, 2021

    @oliviertassinari
    MemberAuthor

    @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.

  19. mnajdova commented on Aug 16, 2021

    @mnajdova
    Member

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

  20. dimitropoulos commented on Aug 16, 2021

    @dimitropoulos
    Contributor

    @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

  21. eric-burel commented on Aug 16, 2021

    @eric-burel
    Contributor

    @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)

  22. mnajdova commented on Aug 16, 2021

    @mnajdova
    Member

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

  23. eric-burel commented on Aug 16, 2021

    @eric-burel
    Contributor

    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.

  24. oliviertassinari commented on Aug 16, 2021

    @oliviertassinari
    MemberAuthor

    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.

  25. oliviertassinari commented on Sep 11, 2021

    @oliviertassinari
    MemberAuthor

    @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.

  26. dkadrios commented on Sep 11, 2021

    @dkadrios

    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 πŸ™ƒ

  27. siriwatknp commented on Sep 13, 2021

    @siriwatknp
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    umbrellaFor grouping multiple issues to provide a holistic view

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions