material-ui icon indicating copy to clipboard operation
material-ui copied to clipboard

[material-ui][Slider] TypeError: color.charAt is not a function error message after upgrade @mui/material to 5.15.14

Open bzhn opened this issue 1 year ago • 10 comments

Steps to reproduce

Link to live example: (example on stackblitz)

Steps:

  1. Update to MUI v.5.15.14 or 5.15.15
  2. Use theme provider with custom theme
  3. Setup palette in custom theme with nested fields like custom.main.blue.dark in the example below
export const theme = createTheme({
  palette: {
    primary: {
      main: '#FFCC00',
      dark: '#FFCC00',
    },
    secondary: {
      main: '#FFCC00',
      dark: '#FFCC00',
    },
    custom: {
      // Error when nesting custom colors
      main: {
        blue: {
          dark: '#FFCC00',
        },
      },
      // The following doesn't lead to error
      // main: '#ffcc00',
    },
  },
});
  1. Add Slider component to your page <Slider aria-label={"Number range"} min={0} max={1234} />
  2. Load the page in your browser

Current behavior

I get the following error when trying to use Slider within the ThemeProvider with custom theme

import { Slider } from "@mui/material";

... some code
<Slider aria-label={"Number range"} min={0} max={1234} />
... some code

gives me the following error message in the console

 ⨯ node_modules\@mui\system\colorManipulator.js (78:0) @ decomposeColor
 ⨯ TypeError: color.charAt is not a function
    at Array.map (<anonymous>)

or on StackBlitz

Error in /turbo_modules/@mui/[email protected]/colorManipulator.js (78:13)
color.charAt is not a function

and the following in my browser

Unhandled Runtime Error

TypeError: color.charAt is not a function

image

Expected behavior

No errors occurs when using palette with nested fields in my custom theme.

Context

No response

Your environment

npx @mui/envinfo
  System:
    OS: Windows 11 10.0.22631
  Binaries:
    Node: 21.6.1 - ~\.nvm\versions\node\v21.6.1\bin\node.EXE
    npm: 10.2.4 - ~\.nvm\versions\node\v21.6.1\bin\npm.CMD
    pnpm: Not Found
  Browsers:
    Chrome: Not Found
    Edge: Chromium (123.0.2420.65)
  npmPackages:
    @emotion/react: ^11.11.3 => 11.11.4
    @emotion/styled: ^11.11.0 => 11.11.5
    @mui/base: ^5.0.0-beta.31 => 5.0.0-beta.40
    @mui/core-downloads-tracker:  5.15.15
    @mui/icons-material: ^5.15.13 => 5.15.15
    @mui/material: ^5.15.15 => 5.15.15
    @mui/material-nextjs: ^5.15.11 => 5.15.11
    @mui/private-theming:  5.15.14
    @mui/styled-engine:  5.15.14
    @mui/system: ^5.15.13 => 5.15.15
    @mui/types: ^7.2.13 => 7.2.14
    @mui/utils:  5.15.14
    @mui/x-date-pickers: ^6.19.7 => 6.19.8
    @types/react: ^18.2.66 => 18.2.74
    react: ^18.2.0 => 18.2.0
    react-dom: ^18.2.0 => 18.2.0
    styled-components: ^6.1.8 => 6.1.8
    typescript: ^5.4.2 => 5.4.3

I use Firefox and Chrome browsers.

Search keywords: color.charAt, Slider, colorManipulator, theme, palette, ThemeProvider

bzhn avatar Apr 04 '24 14:04 bzhn

Not sure if this is related, but I was getting a similar error when trying to add a Switch, while also having the @mui/x-data-grid installed in the project. The only resolution I found was to remove the mui-x package and use the base table.

I see you have another mui-x package. Maybe it’s related?

jbouder avatar Apr 10 '24 11:04 jbouder

I see you have another mui-x package. Maybe it’s related?

@jbouder I doubt it.


This problem emerged as a regression in version 5.15.14 due to #41201. Further details can be found at https://github.com/mui/material-ui/pull/41201#discussion_r1564609862.

ZeeshanTamboli avatar Apr 14 '24 10:04 ZeeshanTamboli

I see you have another mui-x package. Maybe it’s related?

@jbouder I doubt it.

This problem emerged as a regression in version 5.15.14 due to #41201. Further details can be found at #41201 (comment).

Yeah, after digging deeper, the regression seemed to be the real underlying cause. Thanks for the follow up!

jbouder avatar Apr 14 '24 13:04 jbouder

@bzhn I'm not sure why you need such deeply nested palette color fields like theme.palette.custom.main.blue.dark if there aren't multiple properties in the custom and main keys. We also don't document this in our official documentation: https://mui.com/material-ui/customization/palette/. Even though it used to work before v5.15.14, it doesn't make sense to me. Wouldn't it be simpler to define it two levels up? For example, for dark blue, it could be theme.palette.blue.dark and for light blue: theme.palette.blue.light:

export const theme = createTheme({
  palette: {
    primary: {
      main: '#FFCC00',
      dark: '#FFCC00',
    },
    secondary: {
      main: '#FFCC00',
      dark: '#FFCC00',
    },
    blue: {
      main: '#4287f5',
      dark: '#022e73',
      light: '#94bbf7',
    },
  },
});

This is consistent with our documentation: https://mui.com/material-ui/customization/palette/#custom-colors.

ZeeshanTamboli avatar Apr 21 '24 13:04 ZeeshanTamboli

Since the issue is missing key information and has been inactive for 7 days, it has been automatically closed. If you wish to see the issue reopened, please provide the missing information.

github-actions[bot] avatar Apr 29 '24 12:04 github-actions[bot]

Reopening as it's a clear regression: https://stackblitz.com/edit/react-ceuj3r-5w3j9r?file=theme.ts breaks.

oliviertassinari avatar May 04 '24 22:05 oliviertassinari

What is the status of this issue?

rusakovic avatar Jul 29 '24 08:07 rusakovic

Yes a status update would be good. I haven’t been able to update for a while now because of this issue.

jbouder avatar Jul 29 '24 12:07 jbouder

@DiegoAndai This is related to another issue (I could not find it) that we used to discuss. To create a util that handle the theme.palette iteration for all components.

If you still have some capacity, I'd like a help here but it can be done after v6 stable too.

siriwatknp avatar Jul 31 '24 03:07 siriwatknp

@siriwatknp, is this the issue you're referencing? https://github.com/mui/material-ui/pull/42698#issuecomment-2207293293

Sorry I missed this before. I can take a look at it this week.

DiegoAndai avatar Aug 26 '24 20:08 DiegoAndai

This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue. Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

[!NOTE] We value your feedback @bzhn! How was your experience with our support team? If you could spare a moment, we'd love to hear your thoughts in this brief Support Satisfaction survey. Your insights help us improve!

github-actions[bot] avatar Sep 10 '24 17:09 github-actions[bot]