theme-ui creates 2 class names in storybook when using sx prop
See original GitHub issueDescribe the bug
I have an react app. Starting with v0.5.0
, theme-ui
is creating 2 classes when rendered in storybook
for all components whenever the sx
prop is used. (HTML tags with sx
have only one class). One class contains the style of the component, the other class the style from the sx
prop.
When using react-scripts
to render the app, only one class is generated and all css properties are merged in that one class.
There is another issue with storybook
: Not all sx/theme property values are resolved, so the css class(es) contains something like background-color: primary;
. (That’s is not the case when the app is rendered with react-scripts
.)
To Reproduce Steps to reproduce the behavior:
- Clone https://github.com/webcore-it/theme-ui-storybook
- run
yarn
- run
yarn dev
to startstorybook
- Inspect any of the elements to see the generated classes
To check react-scripts
:
- run
yarn start
to start withreact-scripts
- Inspect any of the elements to see the generated class
Expected behavior
Only one class is generated when using storybook
and all theme styles are applied.
Screenshots
2 classes when using storybook
:
1 class when using react-scripts
:
Not resolved theme values:
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:9 (5 by maintainers)
Top GitHub Comments
Thanks for your response. I looked at the Storybook issue board and there are a few tickets with requests to update the dependencies there to emotion 11.
As a workaround if found this comment in a merge request: https://github.com/storybookjs/storybook/pull/13300#issuecomment-783268111
This also worked in my example repo. Now there is one css class and the components are rendered as expected. (Here the only change to
.storybook/main.js
: https://github.com/webcore-it/theme-ui-storybook/commit/62465d1efcc2dbe19ffe9c167413dc9c4d167ee5)I’ve applied this workaround to the actual codebase (yarn monorepo + multiple Gatsby apps) as well, and it worked on the first look.
Feel free to close this issue.
For the yarn users out there - my less configuration-related workaround was:
“resolutions”: { “@emotion/react”: “^11.4.1” },