tailwindcss icon indicating copy to clipboard operation
tailwindcss copied to clipboard

Nested CSS output by Tailwind during dev mode doesn't work in Chrome

Open dhruvkb opened this issue 9 months ago • 5 comments

What version of Tailwind CSS are you using?

For example: v4.0.6

What browser are you using?

This bug appears on Chrome but not in Firefox.

Firefox Chrome
Image Image
No bug, works as expected. Buggy, colors are incorrect.

Reproduction URL

https://play.tailwindcss.com/aKEDzegSx4

Describe your issue

Nested CSS output by Tailwind doesn't work in Chrome. It works well in Firefox. When the output is built for prod, Lightning CSS flattens the output and the final version works in both browsers. Based on this, it is quite likely that this is a Chrome bug.

Is there a way to output flat CSS during development so that this bug can be worked around when in dev mode?

dhruvkb avatar Feb 11 '25 03:02 dhruvkb

Thanks — raised this with my contacts at Google to see if there's any good reason for this or if it's a bug, will report back!

adamwathan avatar Feb 11 '25 10:02 adamwathan

bug in the output from Lightning during dev.

/* doesnt work */
h1 {
  &::after { 
    &:active {
      color: red;
    }
  }
}

/* does work */
h1 {
  &:active {
    &::after {
      color: green;
    }
  }
}

If it helps, my Firefox and Chrome both show the same results for the provided repro URL

argyleink avatar Feb 11 '25 15:02 argyleink

@argyleink This isn't a Lightning thing in this case because we don't use Lightning in Play, instead we just ship the original nested CSS to the browser.

The thing I'm confused by is why two of these work but one doesn't:

/* Works */
.my-class:visited::after {
  color: orange;
}

/* Works */
.my-class {
  &:visited::after {
    color: orange;
  }
}

/* Doesn't work */
.my-class {
  &:visited {
    &::after {
      color: orange;
    }
  }
}

I would've thought all of these would be the same thing 🤔

adamwathan avatar Feb 11 '25 17:02 adamwathan

confirm, what you wrote there is an interop issue. screenshot of this little playground:

Image

i feel like, either Firefox is missing the guards specced for :visited or Safari and Chrome have a nesting bug.

argyleink avatar Feb 11 '25 18:02 argyleink

Yes, in theory all of these should be the same. It looks like a bug in Chrome/Safari's application of the :visited matching restrictions, which are complicated and a little ad-hoc, when mixed with Nesting. (This is one of the reasons Chrome is planning to get rid of them and start treating :visited like a normal pseudo-class that just matches a bit less than today.)

tabatkins avatar Feb 11 '25 20:02 tabatkins