You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’m currently migrating from Material UI v5 to v6 and noticed that component selectors no longer work when using the styled utility from @mui/material.
Here’s a minimal reproduction of what used to work in v5:
After upgrading to v6, Child remains red, the selector no longer applies.
Expected behavior
In v5, this correctly styled the Child green when inside Parent.
Context
If I switch the import to Emotion directly like this:
importstyledfrom'@emotion/styled';
…the selector works again and Child becomes green as expected.
I’m using Emotion and have the SWC plugin installed. Is there something I’ve missed during the v6 migration? Do I need to add or change an importMap in the plugin config to support component selectors with MUI’s styled?
Appreciate any help or clarification, this used to work, and I’d like to stick with the MUI import for consistency and theme integration.
consttransformStyle=(style)=>{// On the server Emotion doesn't use React.forwardRef for creating components, so the created// component stays as a function. This condition makes sure that we do not interpolate functions// which are basically components used as a selectors.if(typeofstyle==='function'&&style.__emotion_real!==style){returnfunctionstyleFunctionProcessor(props){returnprocessStyle(props,style);};}if(isPlainObject(style)){// <<<<<<<<<<<<<<<<<<<<<< the styled component matched this conditionconstserialized=preprocessStyles(style);if(!serialized.variants){returnserialized.style;}returnfunctionstyleObjectProcessor(props){returnprocessStyle(props,serialized);};}returnstyle;};
The component selector passed the isPlainObject because at runtime, React component is an object of { $$typeof: … }. The component selector should not be serialized, instead return it directly to let Emotion handle it.
Steps to reproduce
Stackblitz:
I’m currently migrating from Material UI v5 to v6 and noticed that component selectors no longer work when using the styled utility from @mui/material.
Here’s a minimal reproduction of what used to work in v5:
Current behavior
After upgrading to v6, Child remains red, the selector no longer applies.
Expected behavior
In v5, this correctly styled the Child green when inside Parent.
Context
If I switch the import to Emotion directly like this:
…the selector works again and Child becomes green as expected.
I’m using Emotion and have the SWC plugin installed. Is there something I’ve missed during the v6 migration? Do I need to add or change an importMap in the plugin config to support component selectors with MUI’s styled?
Appreciate any help or clarification, this used to work, and I’d like to stick with the MUI import for consistency and theme integration.
Your environment
npx @mui/envinfo
System:
OS: macOS 15.4.1
Binaries:
Node: 22.14.0 - /nix/store/2ribxb3gi87gj4331m6k0ydn0z90zfi7-nodejs-22.14.0/bin/node
npm: 10.9.2 - /nix/store/2ribxb3gi87gj4331m6k0ydn0z90zfi7-nodejs-22.14.0/bin/npm
pnpm: 9.12.1 - ~/Library/pnpm/pnpm
Browsers:
Chrome: 127.0.6533.120
Edge: 136.0.3240.50
Safari: 18.4
npmPackages:
@emotion/react: 11.14.0 => 11.14.0
@emotion/styled: 11.14.0 => 11.14.0
@mui/icons-material: 6.4.11 => 6.4.11
@mui/material: 6.4.11 => 6.4.11
@mui/system: 6.4.11 => 6.4.11
@mui/x-date-pickers: 7.29.2 => 7.29.2
@types/react: 18.3.20 => 18.3.20
react: 18.3.1 => 18.3.1
react-dom: 18.3.1 => 18.3.1
typescript: 5.8.3 => 5.8.3
Search keywords: component selector, emotion, plugin, v6
The text was updated successfully, but these errors were encountered: