storybook: MUI5 and storybook mixes the `theme` if rendering Docs - which cause an exception
Describe the bug
Material 5 (https://mui.com/core/) uses emotion to style its components. This clashes with storybook and the storybook theme pollutes and wipes out the MUI theme.
To Reproduce
Checkout https://github.com/uwinkler/storybook-problem
Execute yarn && yarn run storybook
Go to a ‘Doc’ page
See screenshot
System System: OS: macOS 11.5.2 CPU: (16) x64 Intel® Core™ i9-9900K CPU @ 3.60GHz Binaries: Node: 16.3.0 - /usr/local/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 7.15.1 - /usr/local/bin/npm Browsers: Firefox: 91.0 Safari: 14.1.2 npmPackages: @storybook/addon-actions: ^6.3.8 => 6.3.8 @storybook/addon-essentials: ^6.3.8 => 6.3.8 @storybook/addon-links: ^6.3.8 => 6.3.8 @storybook/node-logger: ^6.3.8 => 6.3.8 @storybook/preset-create-react-app: ^3.2.0 => 3.2.0 @storybook/react: ^6.3.8 => 6.3.8 Additional context
Add any other context about the problem here
.

About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 19
- Comments: 29 (11 by maintainers)
Commits related to this issue
- switch to next beta of storybook to workaround https://github.com/storybookjs/storybook/issues/16099 — committed to IPG-Automotive-UK/react-ui by dmbarry86 3 years ago
@shilman finally the below solution is worked for me now.
Removing aliases in .storybook/main.js like below
Also experiencing this issue. None of the suggested workarounds fix the issue for me.
Egads!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.4.0-beta.31 containing PR #16613 that references this issue. Upgrade today to the
@nextNPM tag to try it out!Closing this issue. Please re-open if you think there’s still more to do.
Thanks @uwinkler--I’ll take a look today 🙏
There are a few different possible workarounds:
Disable docs https://storybook.js.org/docs/react/essentials/introduction#disabling-addons
Render docs in iframe mode (
docs: { inlineStories: false }): https://storybook.js.org/docs/react/writing-docs/doc-blocks#inline-renderingTry out a possible fix in 6.4:
Then in
.storybook/main.jsset:Invalid build with vite.
Does anyone solve this problem with
"storybook-builder-vite": "^0.1.3"?Here’s a solution that’s better but experimental. cc @ndelangen @tmeasday
modernInlineRenderfeature flag in.storybook/main.jsI tried it out on @uwinkler 's reproduction here:
https://github.com/shilman/sb-mui5-modern-inline-render
Also experiencing this issue. Looking forward for some kind of fix. Thank you!
The repro is here: https://github.com/uwinkler/storybook-16099-issue
You can reproduce the problem yourself:
yarn add @mui/material @emotion/react @emotion/styled<Button/>to theintroduction.stories.mdxfile: https://mui.com/getting-started/usage/This should trigger some problems
Thxs again for your help. This is much appreciated.
Nice one @samuel-joyson!! cc @tooppaaa @ndelangen
@samuel-joyson i can confirm your new reproduction looks ok but throws an exception. thanks for creating it!
hey @shilman please find the link to the repo
https://github.com/samuel-joyson/storybook-mui-issue
reply to: https://github.com/storybookjs/storybook/issues/16099#issuecomment-950292818
@samuel-joyson we’ll do our best to get a solution in 6.5 but don’t get your hopes up. It’s a breaking change to storybook so the earliest we can guarantee a solution is 7.0