Skip to content

[system] recomposeColor() mutates the hsl color object passed to it #49751

Done

Description

@adityajai119

Steps to reproduce

This is a pure function, so a snippet is enough. It runs in Node with @mui/material 9.5.0. The same code fails on master (0ca6dc6).

import { recomposeColor } from '@mui/material/styles';

const color = { type: 'hsl', values: [100, 50, 25] };

console.log(recomposeColor(color)); // 'hsl(100, 50%, 25%)'
console.log(recomposeColor(color)); // 'hsl(100, 50%%, 25%%)'
console.log(color.values); // [100, '50%%', '25%%']

Current behavior

For hsl and hsla colors, recomposeColor() writes the percent strings back into color.values. The second call with the same object returns hsl(100, 50%%, 25%%), which is not valid CSS. The object passed in is changed.

The cause is the hsl branch in packages/mui-system/src/colorManipulator/colorManipulator.ts:

} else if (type.includes('hsl')) {
  values[1] = `${values[1]}%`;
  values[2] = `${values[2]}%`;
}

The rgb and color() branches build a new array, so they do not have this problem.

Expected behavior

recomposeColor() returns hsl(100, 50%, 25%) each time and does not change the object passed to it, as it does for rgb and color() objects.

Context

decomposeColor() returns a color object as is, and the manipulators accept one, so the same object can reach recomposeColor() more than once.

I'm happy to send a PR with a test. The fix is to map the values in the hsl branch instead of assigning to them.

Your environment

  • @mui/material and @mui/system 9.5.0, and master at 0ca6dc6
  • Node.js 24
  • Not browser specific: the unit test fails in both jsdom and Chromium.

AI-assisted: found and reproduced with an AI coding agent; the example above was run locally.

Search keywords: recomposeColor hsl mutate values percent

Activity

  1. added
    status: waiting for maintainer
    on Nov 10, 2026
  2. added
    scope: system
    on Nov 17, 2026
  3. added
    type: bug
    and removed
    status: waiting for maintainer
    on Nov 25, 2026
  4. github-actions commented on Nov 25, 2026

    @github-actions
    Contributor

    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.


    @adityajai119 Thanks again for creating this issue! If you have a moment, we would love to hear your thoughts on how we handled it with this short feedback form.

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

    scope: systemtype: bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions