-
Notifications
You must be signed in to change notification settings - Fork 251
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
CSS order issue. #913
Comments
Came here to report this exact problem. I would expect that styling a styled base component (creating a 'child' styled component) would override styling of that base component. However, since both components get just one css class assigned, it is completely random if the styling will get overwritten. It is dependent on the order at which the css rules are read by the browser, which is not consistent. I would expect one of 2 things to happen:
I'm not familiar with the inner workings of Stitches so I don't know which is the more pragmatic/logical solution here. |
Same issue here 😕 |
Also observing this issue :( @hadihallak, seems pretty similar to #671, any ideas? |
@GeeWizWow There area a few things at work in here like different components extending the same one and two stitches instances at the same time (which is something not currently something we encourage or test against) |
Thanks for the reply!
This is interesting, and removing the second instance of stitches does indeed resolve the issue, as seen here: https://stackblitz.com/edit/nextjs-szzpjc?file=pages%2Findex.js Would you be able to recommend an alternative? We have setup multiple stitches instances as a way to support multiple brands with distinct styling requirements. For example, would the following be a better approach? // packages/primitives/theme
export const { createTheme } = createStitches({ ...empty... });
// packages/brand-one/theme
import { createTheme } from '@primitives/theme';
export const { ... } = createTheme({ ... });
// packages/brand-two/theme
import { createTheme } from '@primitives/theme';
export const { ... } = createTheme({ ... }); |
Awesome. thanks for the quick followup I'm curios now if @jahirfiquitiva and @WDeenik are using a similar setups with multiple Stitches instances |
I shared some stuff regarding this on discord a while ago... I created this to replicate https://codesandbox.io/s/stitches-and-next-themes-forked-04pbg?file=/components/theme-switch.js But I'm using a mix of https://discord.com/channels/752614004387610674/752614004387610678/927691473502228560 https://discord.com/channels/752614004387610674/752614004387610678/927697534103728148 |
We always had just the one Stitches instance, but I am not sure if we used We don't use @jahirfiquitiva Your codesandbox gives an Internal Server Error when I open it |
I checked when we first encountered this problem, that was right before the release of 1.2.6 which had a fix for a very similar problem. When I ran into it again later and responded to this issue I wasn't aware of that new version yet, so there's a chance that the issue was fixed there. We only had one Stitches instance and did not use I cannot reproduce the original bug anymore, but then again it was hard to reproduce back then as well as it only happened occasionally and not very consistent. We'll start extending styled components again (completely avoided it after encountering the bug a couple of times), will report back if we ever run into it again. |
I have a problem with CSS order when trying to overwrite styles of |
Hey @hadihallak, we had a play around with the above this morning, and I'm afraid it wasn't quite what we were looking for, mostly my fault for not having been clear in my examples. Taking the above code again, what we were really hoping to achieve was something along the lines of: // packages/primitives/theme
export const { createTheme } = createStitches({
prefix: '_primitives',
theme: {
// nothing here
},
});
// packages/brand-one/theme
import { createTheme } from '@primitives/theme';
export const { styled } = createTheme({
colors: {
red: 'red',
purple: 'purple',
},
media: {
// some BPs here
},
utils: {
// some utils here,
},
});
// packages/brand-two/theme
import { createTheme } from '@primitives/theme';
export const { styled } = createTheme({
colors: {
green: 'green',
},
media: {
// some **different** BPs here
},
}); Notice how both brands export an instance of the |
Hey @hadihallak, this is actually something that I've brought up before in #534, for which the fix was #546. When the change to using CSSOM was put out, it's something that I explicitly checked with @jonathantneal about, where we had the following conversation
Hopefully the context is helpful! 😄 |
Hey everyone, the original description of the bug perfectly explains the bugs I'm having now on a new project with Hydrogen framework. Basically the overrides and variants have the same specificity in the final css but are before the original (base) class and therefore they don't get applied. It's stitches version I could just use Aside from this the library is great and I love it, thanks! 🙏🏻 |
Bug report
Describe the bug
I'm working on monorepo project which shares components between 3 packages, and sometimes I have some css ordering issues. I made a simple demo in stack blitz which replicates a simplified version of my project:
2 packages that has their own themes:
SSR made in
pages/_document.js
To Reproduce
https://stackblitz.com/edit/nextjs-dzxyti?file=pages/index.js
Expected behavior
ButtonExtended
should have text decoration = none.In my project
I also tried to concatenate all the
getText
into one style tag, but still got the issue. And its happens randomly, on the same component sometimes I got the issue, sometimes I don't.Resulting markup of with the variant checked true:
Resulting css order:
As you can see the variant got overriden by the base css.
Note: order from SSR is working fine (when I disable the javascript everything is ok), the hydration messes up the orders.
Here's the css from SSR:
Video where I have the bug in multiple places:
https://www.youtube.com/watch?v=nVgBbH8Kv_E
The text was updated successfully, but these errors were encountered: