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

ClassName collision creating stitches components with the same css #976

Open
GianDigia opened this issue Mar 4, 2022 · 3 comments
Open
Assignees
Labels
bug Something isn't working
Milestone

Comments

@GianDigia
Copy link

Bug report

Describe the bug

Creating two components with the same CSS the classNames generated is the same. This is particularly bad while composing styles.

To Reproduce

Create two components with the same style. Then create a wrapping stitches component and try to style one of the two child.

const B = styled('div', {
  width: '200px',
  height: '200px',
});

const C = styled('div', {
  width: '200px',
  height: '200px',
});

const A = styled('div', {
  [`& ${B}`]: {
    background: 'red'
  },
});

Calling A with B and C inside

<A>
  <B />
  <C />
</A>

the resulting code will be

<div class="c-jFVahN">
  <div class="c-klsufs"></div>
  <div class="c-klsufs"></div>
</div>

and both B and C will be coloured in red

Expected behavior

The generated classNames should be different
eg.

<div class="c-jFVahN">
  <div class="c-klsufs"></div>
  <div class="c-clmejr"></div>
</div>
@hadihallak hadihallak added the bug Something isn't working label Jun 1, 2022
@hadihallak hadihallak added this to the 1.3.0 milestone Jun 22, 2022
@hadihallak hadihallak self-assigned this Jun 22, 2022
@bakkerjoeri
Copy link

bakkerjoeri commented Aug 18, 2022

I'm pretty consistently running into this problem, with simple patterns like this:

const Media = styled('div');
const Body = styled('div');
const Card = styled('div', {
  display: 'flex',
  variants: {
    direction: {
      row: {
        flexDirection: 'row',
        [`& ${Media}`]: {
          flexShrink: 0,
          flexBasis: '66%',
        },
      },
      column: {
        flexDirection: 'column',
      },
    },
  },
  defaultVariants: { direction: 'column' },
});

Then both Media and Body get those properties applied. Is there any workaround in the meantime? Can I force a different class name?

@azuline
Copy link

azuline commented Aug 18, 2022

You can use a dummy css variable to ensure a unique hash for the styles.

@rntvicente
Copy link

Hi

I have the same problem. Any updates ?

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

No branches or pull requests

5 participants