-
Notifications
You must be signed in to change notification settings - Fork 671
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
theme-ui creates 2 class names in storybook when using sx prop #1530
Comments
Hey @webcore-it! Thanks for the issue. This is a common problem — unfortunately, it's not a bug in our code per se, it's more of a design issue. Let me explain what's happening:
We're passing the theme to one context, and read it from the other. I see a few possibilities of what we can do about it
Neither is a satisfactory solution. cc @lachlanjc what do you think? I added a new label to mark issues about this problem. I'm afraid this is going to be at least 1/4 of all our bug reports, maybe even more. |
Oof. What's the downside of moving Emotion to peerDeps & warn if folks install a version we're not compatible with? |
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:
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 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. |
Thanks for the workaround @webcore-it!
More friction to install peer deps? I tried hard to think of this one, and I don't see any more. |
Let's keep this issue open and close it with a PR moving Emotion to peerDeps (and updating the docs). |
Storybook uses emotion v10 while theme-ui uses v11, causing conflicts (see system-ui/theme-ui#1530). Work around this by aliasing emotion packages to the v11 equivalents inside storybook's manager.
Storybook uses emotion v10 while theme-ui uses v11, causing conflicts (see system-ui/theme-ui#1530). Work around this by aliasing emotion packages to the v11 equivalents inside storybook's manager.
@webcore-it thanks for the solution and the background info! Those exact steps helped solve the issue in our Storybook project (running version Was looking to try out |
FYI I was able to fix that by using pnpm's {
"pnpm": {
"overrides": {
"@emotion/core": "npm:@emotion/react",
"@emotion/styled": "npm:@emotion/styled",
"@emotion/styled-base": "npm:@emotion/styled",
"emotion-theming": "npm:@emotion/react"
}
}
} Note that I must run Storybook via pnpm run storybook |
For the yarn users out there - my less configuration-related workaround was: "resolutions": { |
Our switch to having Emotion as a peer dependency should resolve the majority of cases of this! Please flag if you're still running into this. |
Describe the bug
I have an react app. Starting with
v0.5.0
,theme-ui
is creating 2 classes when rendered instorybook
for all components whenever thesx
prop is used. (HTML tags withsx
have only one class). One class contains the style of the component, the other class the style from thesx
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 likebackground-color: primary;
. (That's is not the case when the app is rendered withreact-scripts
.)To Reproduce
Steps to reproduce the behavior:
yarn
yarn dev
to startstorybook
To check
react-scripts
:yarn start
to start withreact-scripts
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:
The text was updated successfully, but these errors were encountered: