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

Slide component throws error in Pigment project #43750

Closed
ptpittman opened this issue Sep 13, 2024 · 4 comments · Fixed by #44171
Closed

Slide component throws error in Pigment project #43750

ptpittman opened this issue Sep 13, 2024 · 4 comments · Fixed by #44171
Assignees
Labels
bug 🐛 Something doesn't work component: slider This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material package: pigment-css Specific to @pigment-css/*

Comments

@ptpittman
Copy link

ptpittman commented Sep 13, 2024

Steps to reproduce

Link to live example: https://github.com/ptpittman/github-ejtbjs/tree/main

Steps:

  1. Create a NextJS 14 app dir project using MUI and Pigment, as per docs
  2. Attempt to use Slide component with default props and no ThemeProvider set.
  3. Browse to page that uses component, using Safari, Chrome, or any other browser.

Current behavior

I’m migrating a small project into MUI 6/Pigment as a test. I’ve moved all the theme setup over into next.config, DefaultPropsProvider etc, and all is functioning well enough to keep going with it. I have removed ThemeProvider as the docs seem to suggest, which by extension I’d imagine breaks useTheme(). I understand this as a necessity.

However, I use the MUI Slide component on a client nav component, in this sort of way:

      <Slide
        direction="up"
        in={open}
      ><Box></Box></Slide>

This throws:

TypeError: undefined is not an object (evaluating 'theme.transitions.easing’)

I’ve attempted to define easing, as follows, for example:

      <Slide
        direction="up"
        in={open}
        easing={{
          enter: "cubic-bezier(0,1.5,1,1.5)",
          exit: "cubic-bezier(0,1.5,1,1.5)",
        }}
      ><Box></Box></Slide>

But this does not alleviate the error. Looking at the source of @mui/material/Slide/Slide.js, I see that the defaults have an expectation on useTheme returning transitions, as follows:

const Slide = /*#__PURE__*/React.forwardRef(function Slide(props, ref) {
  const theme = useTheme();
  const defaultEasing = {
    enter: theme.transitions.easing.easeOut,
    exit: theme.transitions.easing.sharp
  };
  const defaultTimeout = {
    enter: theme.transitions.duration.enteringScreen,
    exit: theme.transitions.duration.leavingScreen
  };
...

I’d imagine this might be the same for other related elements like Fade, but haven’t checked. Is there anyway around this other than restoring ThemeProvider and running a separate client side theme file outside of next.config?

Expected behavior

Slide element should render using default props in a Pigment context.

Context

Render Slide component without error on a client component, using Pigment CSS and MUI 6.

Your environment

npx @mui/envinfo
  System:
    OS: macOS 14.5
  Binaries:
    Node: 20.16.0 - ~/.nvm/versions/node/v20.16.0/bin/node
    npm: 10.8.1 - ~/.nvm/versions/node/v20.16.0/bin/npm
    pnpm: 9.9.0 - /opt/homebrew/bin/pnpm
  Browsers:
    Chrome: 128.0.6613.138
    Edge: Not Found
    Safari: 17.5
  npmPackages:
    @emotion/react: ^11.13.3 => 11.13.3 
    @emotion/styled: ^11.13.0 => 11.13.0 
    @mui/icons-material: ^6.1.0 => 6.1.0 
    @mui/lab: 6.0.0-beta.9 => 6.0.0-beta.9 
    @mui/material: ^6.1.0 => 6.1.0 
    @mui/material-nextjs: ^6.1.0 => 6.1.0 
    @mui/material-pigment-css: ^6.1.0 => 6.1.0 
    @pigment-css/nextjs-plugin: ^0.0.22 => 0.0.22 
    react: ^18 => 18.2.0 
    react-dom: ^18 => 18.2.0 
    styled-components: 6 => 6.1.8 

Search keywords: Slide, Pigment

@ptpittman ptpittman added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Sep 13, 2024
@zannager zannager added the component: slider This is the name of the generic UI component, not the React module! label Sep 16, 2024
@aarongarciah aarongarciah moved this to Backlog in Material UI Sep 16, 2024
@aarongarciah aarongarciah changed the title Slide component throws error in pigment project [material-ui][Slide] Component throws error in pigment project Sep 16, 2024
@aarongarciah aarongarciah added the package: material-ui Specific to @mui/material label Sep 16, 2024
@aarongarciah aarongarciah changed the title [material-ui][Slide] Component throws error in pigment project Slide component throws error in Pigment project Sep 16, 2024
@aarongarciah aarongarciah assigned siriwatknp and unassigned mnajdova Sep 17, 2024
@mnajdova mnajdova added regression A bug, but worse package: pigment-css Specific to @pigment-css/* labels Oct 14, 2024
@siriwatknp siriwatknp moved this from Backlog to Selected in Material UI Oct 21, 2024
@siriwatknp
Copy link
Member

@ptpittman The workaround is to enable CSS variables:

/** @type {import('next').NextConfig} */
import { withPigment } from '@pigment-css/nextjs-plugin';

import { createTheme } from '@mui/material';

const colors = {
  background: '#343434',
  text: '#000000',
};

const nextConfig = {};

/**
 * @type {import('@pigment-css/nextjs-plugin').PigmentOptions}
 */
const pigmentConfig = {
  transformLibraries: ['@mui/material'],
  theme: createTheme({
+    cssVariables: true,
    palette: {
      primary: {
        main: colors.text,
      },
      background: {
        default: colors.background,
      },
      text: {
        primary: '#FFFFFF',
        inverse: '#000000',
      },
    },
  }),
};

export default withPigment(nextConfig, pigmentConfig);

@siriwatknp siriwatknp added bug 🐛 Something doesn't work and removed regression A bug, but worse status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 21, 2024
@siriwatknp
Copy link
Member

I'd consider this as a bug. I don't think CSS variables is required to use Pigment CSS.

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

@ptpittman How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

@brijeshb42
Copy link
Contributor

Have you tried this recently ? I cloned your repo and tried to run it. I did not run into any issues.
useTheme will still work depending on how you are importing it. It should be imported from @mui/material-pigment-css/useTheme to get the same theme object as declared in the next.config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: slider This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material package: pigment-css Specific to @pigment-css/*
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

6 participants