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

Priority of styleOverrides with custom theme higher than sx when using pigment-css in layout.tsx (Next.js) #43529

Closed
wh5938316 opened this issue Aug 30, 2024 · 4 comments
Assignees
Labels
bug 🐛 Something doesn't work customization: theme Centered around the theming features package: pigment-css Specific to @pigment-css/*

Comments

@wh5938316
Copy link

wh5938316 commented Aug 30, 2024

Steps to reproduce

When using pigment-css as a replacement for @emotion/react in a Next.js project, I noticed that in the layout.tsx file, the priority of styleOverrides in a custom theme takes precedence over the sx prop styling applied directly to MUI components.

Interestingly, this issue does not occur in page.tsx, where the sx prop correctly overrides the styleOverrides in the theme.

I am not sure if this issue also occurs with @emotion/react, but it seems inconsistent and potentially problematic. The sx prop is intended for inline, component-level styling and should ideally have the highest priority.

Github repository

It behaves strangely on Codesandbox; the theme settings configured in next.config.mjs do not take effect.
Codesandbox

Current behavior

next.config.mjs

export default withPigment(nextConfig, {
  theme: createTheme({
    cssVariables: true,
    colorSchemes: { light: true, dark: true },
    typography: {
      fontFamily: 'var(--font-roboto)',
    },
    components: {
      MuiList: {
        styleOverrides: {
          root: {
            padding: '8px',
          },
        },
      },
    }
  }),
  transformLibraries: ['@mui/material'],
});

page.tsx, layout.tsx

<List sx={{
  border: '1px solid'
}}>
  <ListItem>
    <ListItemButton>the</ListItemButton>
  </ListItem>
  <ListItem>
    <ListItemButton>wrong</ListItemButton>
  </ListItem>
  <List
    component="div"
    sx={{
      padding: 4,
    }}>
    <ListItem>
      <ListItemButton>style</ListItemButton>
    </ListItem>
    <ListItem>
      <ListItemButton>priority</ListItemButton>
    </ListItem>
  </List>
</List>

Expected behavior

image

Context

No response

Your environment

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: pigment-css, v6, next.js

@wh5938316 wh5938316 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Aug 30, 2024
@wh5938316
Copy link
Author

To add, after building the project, everything displays correctly. This issue currently only occurs in dev mode.

@zannager zannager added the package: pigment-css Specific to @pigment-css/* label Sep 2, 2024
@DiegoAndai
Copy link
Member

This one should be fixed with mui/pigment-css#199

@siriwatknp siriwatknp added bug 🐛 Something doesn't work customization: theme Centered around the theming features and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Sep 10, 2024
@Janpot
Copy link
Member

Janpot commented Sep 11, 2024

This will be fixed after mui/pigment-css#226 is released.

Here's a codesandbox with the patched package: https://codesandbox.io/p/github/wh5938316/mui-v6-pigment-css/csb-ymg78v/draft/floral-dream

Screenshot 2024-09-11 at 16 48 23

@Janpot Janpot closed this as completed Sep 11, 2024
Copy link

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 @wh5938316! 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work customization: theme Centered around the theming features package: pigment-css Specific to @pigment-css/*
Projects
Status: Done
Development

No branches or pull requests

5 participants