-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
Updating from v5 to v6 doesnt work: createStyled.js:26 Uncaught TypeError: Cannot assign to read only property 'theme' of object '#<Object>' #44343
Comments
I think the error came from using a styled component and passing the theme to it and the theme was imported from the theme file (createTheme({}) |
Hey @BennyAlex, thanks for the report! Could you provide a minimal reproduction? This would help a lot. A repo sharing your project would be perfect. Thank you! |
I have the same issue here with a component. Exact same error message after upgrading to v6.
Is there any upgrade guidance for who use styled? Any tools out there that can validate our stylings? |
Hey @visualjeff, thanks for the report! Could you provide a minimal reproduction? This would help a lot. A live example would be perfect. A repo or a StackBlitz sandbox would work. Thank you! |
I think I figured out our issue while creating repro code. Don't pass the theme down as a prop so you can use it to style a component.
|
thats what I also wrote here I think the error came from using a styled component and passing the theme to it and the theme was imported from the theme file (createTheme({}) so thats basically the solution to remove the theme prop from styled components |
So I think we can close the issue. |
@BennyAlex so I understand you were able to solve the issue on your side as well? |
Since the issue is missing key information and has been inactive for 7 days, it has been automatically closed. If you wish to see the issue reopened, please provide the missing information. |
i just ending the migration from v4 to v6 and faced the same issue but it didn't come from |
and i think the reason is like @BennyAlex said when you trying to insert the theme and when you take the global theme and use it inside the styled component the scop theme is trying to override the global theme and the global theme is a frozen object and then you get this error TypeError |
Not sure if withTheme is still needed or even supported. Have you tried without it? |
face the same issue too. ⨯ ../../node_modules/@mui/system/esm/createStyled/createStyled.js (26:1) @ attachTheme |
it seems that we should not pass const IconButtonStyle = styled(MuiIconButton, {
shouldForwardProp: (prop) => prop !== 'variant' && prop !== 'shape',
})(({ theme, variant, shape, color }: StyleProps) => ({
position: 'relative',
'::after': {
|
you are right the withTheme is not needed but it's still in supported this code is from the prevues version and the codemod to v6 isn't replace it then i deleted it and every thing ok |
yes as you can see this is the same, |
Hey @MosheHM, from this: "then i deleted it and every thing ok" I understand you were able to solve your issue? @tianyingchun seems like your case is the same and can also be solved, as you mention: #44343 (comment) |
I avoid passing theme directly into styled's component library
获取 Outlook for iOS<https://aka.ms/o0ukef>
…________________________________
发件人: Diego Andai ***@***.***>
发送时间: Thursday, November 28, 2024 1:22:55 AM
收件人: mui/material-ui ***@***.***>
抄送: Yingchun Tian ***@***.***>; Mention ***@***.***>
主题: Re: [mui/material-ui] Updating from v5 to v6 doesnt work: createStyled.js:26 Uncaught TypeError: Cannot assign to read only property 'theme' of object '#<Object>' (Issue #44343)
Hey @MosheHM<https://github.com/MosheHM>, from this: "then i deleted it and every thing ok" I understand you were able to solve your issue?
@tianyingchun<https://github.com/tianyingchun> seems like your case is the same and can also be solved, as you mention: #44343 (comment)<#44343 (comment)>
―
Reply to this email directly, view it on GitHub<#44343 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAVTWY7FXRUBJKBWAKX3NVT2CX5W7AVCNFSM6AAAAABRLKYC6CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMBUGQYTIMJUGM>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Hi @DiegoAndai, indeed that solve the problem |
Closing this as we have found the solution. If you're dealing with the same problem, please checkout this comment. |
This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue. Note @BennyAlex 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. |
Steps to reproduce
I am trying to upgrade to v6 and also used the codemods but I am seeing this error.
Current behavior
No response
Expected behavior
No response
Context
No response
Your environment
npx @mui/envinfo
Search keywords: 'theme' of object, reateStyled.js:26
The text was updated successfully, but these errors were encountered: