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.

nested css selector element& broken in emotion 11

See original GitHub issue

I’m upgrading from emotion 10 to 11 and experiencing some changes in how my “button” selector works which I apply to button and a elements.

.button {
    color: blue

    &:hover, &:focus, &.is-active {
        &:enabled, a& {
            color: red
        }
    }
}

This previously generated the following correct css

/* for :enabled <button> elements */
.button:hover:enabled,
.button:focus:enabled,
.button.is-active:enabled,

/* <a> elements styled as buttons */
a.button:hover,
a.button:focus,
a.button.is-active {
    color: red
}

as shown and isolated in https://codesandbox.io/s/modest-lederberg-db4bt?file=/src/App.js

After upgrading to emotion 11 the following css is generated which breaks it.

.button:hover:enabled,
.button:focus:enabled,
.button:hover a&,
.button:focus a&{
    background:blue
}

To reproduce:

See the sandbox which isolates the issue. https://codesandbox.io/s/relaxed-shamir-yleem?file=/src/App.js Its the same as above, I just swapped out the dependencies.

Expected behavior:

Generated CSS should be the same as previously in emotion 10.

  • react version: 17.0.2 (also seen with 16.14)
  • @emotion/react version: 11.4.1

As also the stylis version changed I already raised an issue over there at https://github.com/thysultan/stylis.js/issues/274

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Andaristcommented, Sep 29, 2021

Not yet - being busy at the moment, hope to get back to this later this week but no promises.

0reactions
joernroedercommented, Oct 4, 2021

@Andarist Wow, thank you so much for looking into this and your hard work ❤️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nested selectors behaviour #235 - emotion-js/emotion - GitHub
This smells funky, and it creates a semantic rift between what it means to nest selectors and what it means to nest elements....
Read more >
Nested Selectors - Emotion
Sometimes it's useful to nest selectors to target elements inside the current class or React component. An example with an element selector is...
Read more >
React Emotion Styled Component: Class selector not working
I have built a switch the same way and using a class selector I can change the CSS of another component when the...
Read more >
Why We're Breaking Up with CSS-in-JS - DEV Community ‍ ‍
My SASS components are usually flat and I only nest when doing something like the lobotomized owl. For getting colors or dimensions from...
Read more >
Selectors - W3C
In CSS, pattern matching rules determine which style rules apply to elements in the document tree. These patterns, called selectors, may range from...
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