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][AppRouterCacheProvider] enableCssLayer not working as expected #42109

Open
mtr1990 opened this issue May 3, 2024 · 5 comments
Open
Assignees
Labels
nextjs package: material-ui Specific to @mui/material

Comments

@mtr1990
Copy link

mtr1990 commented May 3, 2024

Steps to reproduce

I couldn't reproduce on codesandbox so I'll attach the repo here

https://github.com/mtr1990/test-css-vars

Current behavior

    <AppRouterCacheProvider
      options={{
        key: 'css',
        prepend: true,
        // enableCssLayer: true,
      }}
    >
      <CssBaseline />
      <CssVarsProvider theme={theme}>{children}</CssVarsProvider>
    </AppRouterCacheProvider>

When enableCssLayer is false some components are broken like:
2

But styles are overridable

When enableCssLayer is true works fine. But the style cannot be overridden
1

Expected behavior

Ability to override type when enableCssLayer = true

Present
image

Expect:
image

Context

No response

Your environment

No response

Search keywords: enableCssLayer

@mtr1990 mtr1990 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label May 3, 2024
@zannager zannager added package: system Specific to @mui/system customization: css Design CSS customizability labels May 3, 2024
@danilo-leal danilo-leal changed the title [AppRouterCacheProvider] enableCssLayer not working as expected [material-ui][AppRouterCacheProvider] enableCssLayer not working as expected May 7, 2024
@danilo-leal danilo-leal added package: material-ui Specific to @mui/material nextjs and removed package: system Specific to @mui/system customization: css Design CSS customizability labels May 7, 2024
@brijeshb42
Copy link
Contributor

brijeshb42 commented May 7, 2024

I found that the issue is due to invalid generated css causing other css to not be applied when enableCssLayer is enabled.

.css-1lszvsm-MuiSlider-thumb{position:absolute;width:20px;height:20px;box-sizing:border-box;border-radius:50%;outline:0;background-color:currentColor;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;-webkit-transition:box-shadow 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,left 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,bottom 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;transition:box-shadow 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,left 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,bottom 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;}.css-1lszvsm-MuiSlider-thumb::before{position:absolute;content:"";border-radius:inherit;width:100%;height:100%;box-shadow:var(--md-demo-shadows-2);}.css-1lszvsm-MuiSlider-thumb::after{position:absolute;content:"";border-radius:50%;width:42px;height:42px;top:50%;left:50%;-webkit-transform:translate(-50%, -50%);-moz-transform:translate(-50%, -50%);-ms-transform:translate(-50%, -50%);transform:translate(-50%, -50%);}.css-1lszvsm-MuiSlider-thumb.Mui-disabled:hover{box-shadow:none;}.css-1lszvsm-MuiSlider-thumb:hover,.css-1lszvsm-MuiSlider-thumb.Mui-focusVisible{box-shadow:0px 0px 0px 8px rgba(var(--md-demo-palette-primary-mainChannel) / 0.16);}@media (hover: none){.css-1lszvsm-MuiSlider-thumb:hover,.css-1lszvsm-MuiSlider-thumb.Mui-focusVisible{box-shadow:none;}}.css-1lszvsm-MuiSlider-thumb.Mui-active{box-shadow:0px 0px 0px 14px rgba(var(--md-demo-palette-primary-mainChannel) / 0.16);}

top:50%;
-webkit-transform:translate(-50%, -50%);
-moz-transform:translate(-50%, -50%);
-ms-transform:translate(-50%, -50%);
transform:translate(-50%, -50%);

Note that the last 5 properties are stray without any wrapped selector. Need to look more into why this is happening.

cc: @siriwatknp

@brijeshb42 brijeshb42 removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label May 7, 2024
@siriwatknp
Copy link
Member

siriwatknp commented May 15, 2024

I found that the issue is due to invalid generated css causing other css to not be applied when enableCssLayer is enabled.

When enabled or not enabled?

Ability to override type when enableCssLayer = true

What do you mean by "But the style cannot be overridden"? The undefined layer will override the @mui layer by default. This is how CSS layer works.

@brijeshb42
Copy link
Contributor

when enableCssLayer is enabled

@mtr1990
Copy link
Author

mtr1990 commented May 17, 2024

When enabled or not enabled?

My behavior is to style in .jsx file with: styled (enableCssLayer ===true)

Ex: export const StyledToaster = styled(SonnerToaster)(({ theme }) => {...}

And it cannot override existing properties: width, height...

I also tried styling it in the .css file. However, it cannot override existing properties such as width and height.

@layer test {
  :where([data-sonner-toast]) :where([data-icon]) {
    color: red;
    background: green;
    width: 100px;
    height: 100px;
  }
}

:where([data-sonner-toast]) :where([data-icon]) {
  color: red;
  background: green;
  width: 100px;
  height: 100px;
}
image

with enableCssLayer = false the override works fine. but components like sliders will break.

image

@mtr1990
Copy link
Author

mtr1990 commented May 18, 2024

[Update] with enableCssLayer = false I change:

styleOverrides: {
    thumb: ({ theme }) => ({
      borderWidth: 1,
      borderStyle: 'solid',
      width: SIZE.thumb.medium,
      height: SIZE.thumb.medium,
      boxShadow: theme.customShadows.z1,
      color: theme.vars.palette.common.white,
      borderColor: varAlpha(theme.vars.palette.grey['500Channel'], 0.08),
      '&::before': {
        opacity: 0.4,
        boxShadow: 'none',
        width: 'calc(100% - 4px)',
        height: 'calc(100% - 4px)',
        backgroundImage: `linear-gradient(180deg, ${theme.vars.palette.grey[500]} 0%, ${varAlpha(theme.vars.palette.grey['500Channel'], 0)} 100%)`,
        [stylesMode.dark]: { opacity: 0.8 },
      },
    }),
    thumbSizeSmall: { width: SIZE.thumb.small, height: SIZE.thumb.small },
}

To:

  styleOverrides: {
    root: ({ theme }) => ({
      [`& .${sliderClasses.thumb}`]: {
        borderWidth: 1,
        borderStyle: 'solid',
        width: SIZE.thumb.medium,
        height: SIZE.thumb.medium,
        boxShadow: theme.customShadows.z1,
        color: theme.vars.palette.common.white,
        borderColor: varAlpha(theme.vars.palette.grey['500Channel'], 0.08),
        '&::before': {
          opacity: 0.4,
          boxShadow: 'none',
          width: 'calc(100% - 4px)',
          height: 'calc(100% - 4px)',
          backgroundImage: `linear-gradient(180deg, ${theme.vars.palette.grey[500]} 0%, ${varAlpha(theme.vars.palette.grey['500Channel'], 0)} 100%)`,
          [stylesMode.dark]: { opacity: 0.8 },
        },
      },
    }),
    sizeSmall: {
      [`& .${sliderClasses.thumb}`]: { width: SIZE.thumb.small, height: SIZE.thumb.small },
    },
 }   

to fix. The problem may lie in the slots

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
nextjs package: material-ui Specific to @mui/material
Projects
None yet
Development

No branches or pull requests

5 participants