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.

[JIT] Class based variant bug when chaining

See original GitHub issue

What version of Tailwind CSS are you using?

v2.2.7

What build tool (or framework if it abstracts the build tool) are you using?

postcss v8.3.6

What version of Node.js are you using?

v14.15.5

What browser are you using?

chrome

What operating system are you using?

macOS

Reproduction repository

https://github.com/minimit/twbug-class-variant-chain

Describe your issue

When using custom variants with classes instead of pseudo selectors, and chaining multiple variants, the output is wrong.

This is the code of the addVariant.

    addVariant('class', ({ modifySelectors, separator }) => {
      modifySelectors(({ className }) => {
        return `.${e(`class${separator}${className}`)}.class`
      })
    })

This is the code of the apply or html class.

.test-class {
  @apply sm:class:hidden;
}

This is the output.

@media (min-width: 640px) {
    {
         display: none
    }
}

This is the desired output.

@media (min-width: 640px) {
    .test-class.class {
         display: none
    }
}

Seems also html class does the same.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
RobinMalfaitcommented, Aug 27, 2021

Hey! Thank you for your bug report! Much appreciated! 🙏

I’ve been debugging on what’s going on here exactly. The issue is not that custom variants like that don’t work, the problem currently is what the result of the modified selector is.

I will make a PR to fix this, however there is an easier solution you can already apply for your use case:

 addVariant('class', ({ modifySelectors, separator }) => {
      modifySelectors(({ className }) => {
-       return `.${e(`class${separator}${className}`)}.class`
+       return `.class.${e(`class${separator}${className}`)}`
      })
    })

Essentially moving the .class in front. The reason why this works and the others don’t is because of an internal assumption where we update the last class of a selector, however, when you eventually have .hidden.class the last class is class, which should not be updated.

I’ll leave this open for now and will link my PR once it is ready, but in the meantime my small solution above should fix your issue for now.

0reactions
minimitcommented, Jan 10, 2022

Thanks works like a charm you delivered 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

As a JS Developer, This Is What Keeps Me Up at Night - Toptal
A class constructor creates an instance of the class. A constructor in JavaScript is just a plain old function that returns an object....
Read more >
Override Tailwind CSS @apply directive on chained selectors
1 Answer 1 · 2. I'm not sure setting ! · can you set the dynamic class to solve this problem without !important...
Read more >
Exploit writing tutorial part 10 : Chaining DEP with ROP
In the previous tutorials, I have explained the basics of stack based overflows and how they can lead to arbitrary code execution.
Read more >
GATK - Broad Institute
A genomic analysis toolkit focused on variant discovery. The GATK is the industry standard for identifying SNPs and indels in germline DNA and...
Read more >
Functions & Directives - Tailwind CSS
@tailwind base; /** * This injects Tailwind's component classes and any component ... focus, * responsive, dark mode, and other variants of each...
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