Skip to content
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

Variants and css prop styles do not apply #441

Closed
8th713 opened this issue Feb 27, 2021 · 2 comments · Fixed by #450
Closed

Variants and css prop styles do not apply #441

8th713 opened this issue Feb 27, 2021 · 2 comments · Fixed by #450
Assignees
Labels
bug Something isn't working P1

Comments

@8th713
Copy link

8th713 commented Feb 27, 2021

Bug report

Describe the bug

Div component variants and css prop styles do not apply.

To Reproduce

https://codesandbox.io/s/stitches-bug-su9fq?file=/src/App.tsx

Expected behavior

Variant and css prop styles are applied.

System information

  • Version of Stitches: 0.1.0-canary.12

Additional context

If multiple stitch components have the same style, the component's base CSS rules will be duplicated and will take precedence over the additional CSS rules.

@joe-bell
Copy link

Try this approach instead, it should give you the behaviour you're looking for here:

const Div = styled('div', {
  margin: 8,
  variants: {
    bg: {
      pink: {
        backgroundColor: 'pink',
      },
      red: {
        backgroundColor: 'red',
      },
      green: {
        backgroundColor: 'green',
      },
    },
  },
  defaultVariants: {
    bg: 'pink'
  }
})

@peduarte peduarte added beta bug Something isn't working P1 labels Mar 1, 2021
@peduarte
Copy link
Contributor

peduarte commented Mar 1, 2021

Hmm. This most definitely shouldnt be happening.

Looks like we have an issue with the CSS injection of base styles. It gets added twice, and the secon time later in the stylesheet, so it overrides the variants.

Here's the generated CSS

.sxbjjes {
  margin: 8px;
  background-color: pink;
}
.sxbjjesy27ki--bg-red {
  background-color: red;
}
.sxbjjesfqayk--bg-green {
  background-color: green;
}
.sxbjjes2qnvx--css {
  background-color: lime;
}
.sxbjjes {
  margin: 8px;
  background-color: pink;
}
.sxbjjeszz1ir--typography-md {
  font-size: 1.25rem;
}
.sxbjjesibggw--css {
  background-color: skyblue;
}

A bit more info, this happens becuase the generated base class for the Div and Title are the same. They are the same because both components share the exact same base styles.

@jonathantneal perhaps this was done as an optimisation, but its causing specificity issues, similar to the ones we had with atomic css

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants