question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple of the same variants didn't applied properly on responsive styles

See original GitHub issue

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:

// stitch.config.js
export const { styled } = createCss({
  ...
  media: {
    phone: `(min-width: 420px)`,
    tablet: `(min-width: 720px)`,
    desktop: `(min-width: 1024px)`,
    wide: `(min-width: 1536px)`,
  },
  ...
})

And then a Flex component that received a justify props and set it according to its variants

// Flex.js
const Flex = styled('div', {
  ...,
  variants: {
    justify: {
      start: { justifyContent: "flex-start" },
      center: { justifyContent: "center" },
      end: { justifyContent: "flex-end" },
      between: { justifyContent: "space-between" },
      evenly: { justifyContent: "space-evenly" }
    },
  },
  ...
})

// usage of Flex
return (
  <Flex justify={{ 
        "@initial": "start",
        "@phone": "center",
        "@tablet": "end",
        "@desktop": "between",
        "@wide": "end"
  }}>
   {...items}
  </Flex>
)

When I run it, the media query for @tablet never applied on the <Flex />

You can try this too:

justify={{ 
  "@initial": "start",
  "@phone": "center",
  "@tablet": "end",
  "@desktop": "end",
  "@wide": "end"
}}

And the end variant will only be applied on the @wide screen. The tablet @tablet and @desktop screen still has the center variant.

Here’s a sandbox demo: https://codesandbox.io/s/stitches-responsive-problem-r43lf

System information

  • OS: [macOS]
  • Browser: tried on Chrome, Safari TP, and Firefox Nightly
  • Version of Stitches: Tried on 0.2.5 and 1.0.0-canary.10

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:18 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
hadihallakcommented, Dec 2, 2021

Published under 1.2.6 🎉

5reactions
hadihallakcommented, Nov 18, 2021

This is now fixed in a release candidate under the version 1.2.6-0 under a canary tag. Should be pretty stable if you’d like to upgrade now but expect a final release sometime next week once we finish migrating our products to use the updated version.

Please, don’t hesitate in providing us with any feedback regarding this release. very much appreciated 🙏

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiple of the same variants didn't applied properly ... - GitHub
Describe the bug. When 2 or more of the same variants are applied on different responsive styles breakpoints, only the last one is...
Read more >
Responsive Design Tutorial: Media Query Examples & More
Use media queries and pseudo-elements for design and give your mobile users a responsive mobile experience—in pure CSS.
Read more >
Responsive images - Learn web development | MDN
Responsive image technologies were implemented recently to solve the problems indicated above by letting you offer the browser several image ...
Read more >
Some Tailwind styles not working in production with Next.js
In case anyone is having issues with not updating dom changes accordingly. Check if imports and filenames are written with the same case!...
Read more >
Variants - Stitches.dev
() => <Button color="violet">Button</Button>;. A variant accepts the same style object as the base styles. Multiple variants.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found