-
Notifications
You must be signed in to change notification settings - Fork 255
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
Multiple of the same variants didn't applied properly on responsive styles #725
Comments
@jonathantneal can you verify? thanks! |
I’m not certain this is a bug, but is instead a misunderstanding of media queries, and mostly because the old syntax for media queries is not very helpful to authors. I recommend using the newer media query ranges syntax in your import { createStitches } from "@stitches/react";
export const { styled } = createStitches({
media: {
phone: "(width < 720px)",
tablet: "(720px <= width < 1024px)",
desktop: "(1024px <= width < 1536px)",
wide: "(1536px <= width)",
},
}); With these breakpoints, I verified that the correct styles were applying to the correct breakpoints in the correct order. https://codesandbox.io/s/stitches-responsive-problem-forked-ghszg?file=/src/stitches.config.js |
Sorry @jonathantneal, I tried your sandbox but it still has not applied correctly <Flex
justify={{
'@initial': 'start',
'@phone': 'center',
'@tablet': 'end',
'@desktop': 'between',
'@wide': 'end',
}}
> The |
You are right, @vasilenka! I have been investigating this. While I don’t understand why it is happening, it has something to do with |
@jonathantneal I made another fork of the sandbox and try to explore the problem, you can find it here: https://codesandbox.io/s/stitches-responsive-problem-forked-nz3ui You may already notice it, but here're what I found: Using the old media syntax
|
@vasilenka @jonathantneal It worked for me by placing import { createStitches } from "@stitches/react";
export const { styled } = createStitches({
media: {
phone: "(width < 720px)",
tablet: "(720px <= width < 1024px)",
desktop: "(1024px <= width < 1536px)",
wide: "(1536px <= width)",
},
...
}); |
We haven’t had a chance to look into this much deeper. However, we can see the problem in the final output of the CSS. You will see that the shared key/value pairs under different media queries get mixed together. --sxs {
--sxs: 2 c-kZriBw
}
@media {
.c-kZriBw {
display: flex;
width: 100vw;
height: 100vh;
}
}
--sxs {
--sxs: 3 c-kZriBw-awKDG-justify-start c-kZriBw-ceSYxj-justify-center c-kZriBw-cgrpcB-justify-between c-kZriBw-lfUpcg-justify-end
}
@media {
.c-kZriBw-awKDG-justify-start {
justify-content: flex-start;
}
@media (max-width: 719.9375px) {
.c-kZriBw-ceSYxj-justify-center {
justify-content: center;
}
}
@media (min-width: 1024px) and (max-width: 1535.9375px) {
.c-kZriBw-cgrpcB-justify-between {
justify-content: space-between;
}
}
@media (min-width: 1536px) {
@media (min-width: 720px) and (max-width: 1023.9375px) {
.c-kZriBw-lfUpcg-justify-end {
justify-content: flex-end;
}
}
}
} |
I have been dealing with this issue today, and I did find a couple of things that seem to matter;
export const {
styled,
css,
globalCss,
keyframes,
getCssText,
theme,
createTheme,
config,
} = createStitches({
media: {
// IMPORTANT! The sequence here seems to be important!
laptops: "(1024px <= width)",
tablets: "(768px <= width < 1024px)",
phones: "(width < 768px)",
},
theme: {
....
<WeLoveStichCompoenent
screenSize={{
"@laptops": "laptop",
"@tablets": "tablet",
"@phones": "phone",
"@initial": "phone",
}}
/> Notice that I mirror the sequence I have in my |
@vasilenka would you mind validating that #869 is working as you'd expect? |
@hadihallak sorry for taking so long to get back to this I'm confused on how or which version should I test it with? there're lots of different canary version on Codesandbox Also, I tried it on It's just testing the |
@vasilenka No worries and thank you so much for taking a look again. Thanks again, super helpful! |
this is now fixed in #875 and is pending release so i'm gonna keep the issue open until we release it publicly |
This is now fixed in a release candidate under the version Please, don't hesitate in providing us with any feedback regarding this release. very much appreciated 🙏 |
thank you for the hard work! |
Thanks for this, I just want to verify my implementation as it seems to not be working using 1.2.6-0 in codesandbox: https://codesandbox.io/s/stitches-responsive-problem-forked-umghp?file=/src/App.js |
Hey @coreybruyere 👋 |
thanks @hadihallak - is the reasoning for this going to be documented anywhere? |
Published under |
Bug report
Previously I've created a discussion in https://github.com/modulz/stitches/discussions/724
Describe the bug
When 2 or more of the same variants are applied on different responsive styles breakpoints, only the last one is applied properly on the component.
To Reproduce
I've got this config:
And then a Flex component that received a justify props and set it according to its variants
When I run it, the media query for
@tablet
never applied on the<Flex />
You can try this too:
And the
end
variant will only be applied on the@wide
screen. The tablet@tablet
and@desktop
screen still has thecenter
variant.Here's a sandbox demo: https://codesandbox.io/s/stitches-responsive-problem-r43lf
System information
The text was updated successfully, but these errors were encountered: