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

Wrong CSS specificity #1045

Open
oliviertassinari opened this issue Feb 25, 2019 · 6 comments
Open

Wrong CSS specificity #1045

oliviertassinari opened this issue Feb 25, 2019 · 6 comments
Assignees
Labels
bug It went crazy and killed everyone. complexity:moderate We talked about it, you can do it! help wanted
Milestone

Comments

@oliviertassinari
Copy link
Contributor

oliviertassinari commented Feb 25, 2019

Take the following style as an input:

const style = {
  root: {
    "&:hover": {
      "& .icon": {
        color: "red"
      }
    },
    "&.active": {
      "& .icon": {
        color: "blue"
      }
    }
  },
};

Expected behavior:
I would expect the following CSS injected into the page:

.root-0-0-1:hover .icon {
  color: red;
}
.root-0-0-1.active .icon {
  color: blue;
}

Describe the bug:
The following CSS is injected in the page:

.root-0-0-1.active .icon {
  color: blue;
}
.root-0-0-1:hover .icon {
  color: red;
}

Codesandbox link:

https://codesandbox.io/s/yjyqmo4vqv

Versions (please complete the following information):

  • jss: 10.0.0-alpha.11
@kof
Copy link
Member

kof commented Feb 25, 2019

Do you know if its a new bug in v10 or has been there in v9 too?

@kof kof added bug It went crazy and killed everyone. complexity:moderate We talked about it, you can do it! labels Feb 25, 2019
@oliviertassinari
Copy link
Contributor Author

It has probably been here for a long time: same with v9: https://codesandbox.io/s/qo00j8549.

@oliviertassinari
Copy link
Contributor Author

The workaround:

const style = {
  root: {
    "&:hover": {
      "& .icon": {
        color: "red"
      }
    },
    "&.active": {
-     "& .icon": {
+     "&& .icon": {
        color: "blue"
      }
    }
  },
};

Featured in mui/material-ui#14650.

@kof kof self-assigned this Mar 1, 2019
@kof
Copy link
Member

kof commented Mar 1, 2019

Just reproduced it with a test, it's weird that this workaround helps

@kof
Copy link
Member

kof commented Mar 1, 2019

Ah it's not weird, workaround works because you increase specificity there

@vlazh
Copy link

vlazh commented May 3, 2020

Are there any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It went crazy and killed everyone. complexity:moderate We talked about it, you can do it! help wanted
Projects
None yet
Development

No branches or pull requests

4 participants