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

[material-ui] Make the palette always return new light and dark object #44059

Merged
merged 1 commit into from
Oct 10, 2024

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented Oct 10, 2024

The issue popup in #43708 when there are multiple calls from createTheme.

The root cause comes from the palette.background is not being recreated every time that the createPalette is called,
so if palette.background.* is mutated, it affect all of the instances.

The fix is to wrap the light and dark object in a function and call them inside the createPalette. Tests added.


@siriwatknp siriwatknp added the enhancement This is not a bug, nor a new feature label Oct 10, 2024
@siriwatknp siriwatknp requested review from Janpot and a team October 10, 2024 08:03
@siriwatknp siriwatknp added customization: theme Centered around the theming features package: material-ui Specific to @mui/material labels Oct 10, 2024
@mui-bot
Copy link

mui-bot commented Oct 10, 2024

Netlify deploy preview

https://deploy-preview-44059--material-ui.netlify.app/

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against 054401c

Copy link
Member

@Janpot Janpot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good 👍

@mnajdova mnajdova merged commit 66dfe8b into mui:master Oct 10, 2024
22 checks passed
expect(palette1.background.default).to.equal('#fff');
expect(palette2.background.default).to.equal('#fff');

palette1.background.default = '#000';
Copy link
Member

@oliviertassinari oliviertassinari Oct 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, we had the same bug since Material UI v1, I guess.

Comment on lines -259 to +267
const modes = { dark, light };
const modes = { dark: getDark(), light: getLight() };
Copy link
Member

@oliviertassinari oliviertassinari Oct 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should refactor this then? It sounds wasteful to call getDark() or the other to then throw away the object: #44075.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customization: theme Centered around the theming features enhancement This is not a bug, nor a new feature package: material-ui Specific to @mui/material
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants