Skip to content

[system] Verify correctiveness of theme during createMuiThemeΒ #17485

@zhming0

Description

@zhming0
  • I have searched the issues of this repository and believe that this is not a duplicate.

Summary πŸ’‘

This feature will ensure correctiveness of theme's being verified during createMuiTheme.

Alternatively, a function to verify correctness of the theme could be helpful too.

Examples 🌈

// This should throw an error during initialization
const theme = createMuiTheme({
  palette: {
    primary: 'random string'
  }
})

Motivation πŸ”¦

At the moment, Typescript can enforce the correctness of theme structure, but it can't verify the content of them. The content of theme seems to get verified during runtime when a component is consuming a part of it.

This causes an issue that front-end page crashes when you navigate to a MUI component that consume an invalid part of theme via decomposeColor function. For above example, you would see Material-UI: unsupported XXXX color and page crashes

At this moment, to ensure the theme is valid, we will have to either:

  1. unit-test all components's behavior under custom theme (renderWithTheme etc..)
  2. make a dedicated test scaffolding for theme to verify the content
  3. manually check all components on UI

It'd be great if createMuiTheme can create a safety net for us.

Alternative

Handle the error thrown by decomposeColor gracefully

Metadata

Metadata

Assignees

No one assigned

    Labels

    scope: systemThe system, the design tokens / styling foundations used across components. eg. @mui/system with MUItype: new featureExpand the scope of the product to solve a new problem.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions